Here we’re going to talk all about Permissions in Unix terminal?
When it comes to reading, writing or executing files in unix we need to play around with the permissions! So today we are going to talk all about permissions in unix terminal (chmod).
Permissions are important thing in unix, when it comes to files and folders access.
How to change directory permissions in Linux
To change directory permissions in Linux, use the following:
chmod +rwx filename to add permissions.
chmod -rwx directoryname to remove permissions.
chmod +x filename to allow executable permissions.
chmod -wx filename to take out write and executable permissions.
Note that “r” is for read, “w” is for write, and “x” is for execute.
This only changes the permissions for the owner of the file.
How to Change Permissions in Numeric Code in Linux – Watch it in below video
You may need to know how to change permissions in numeric code in Linux, so to do this you use numbers instead of “r”, “w”, or “x”.
0 = No Permission
1 = Execute
2 = Write
4 = Read
Basically, you add up the numbers depending on the level of permission you want to give.
Permission numbers are:
0 = —
1 = –x
2 = -w-
3 = -wx
4 = r-
5 = r-x
6 = rw-
7 = rwx
For example:
chmod 777 foldername will give read, write, and execute permissions for everyone.
chmod 700 foldername will give read, write, and execute permissions for the user only.
chmod 327 foldername will give write and execute (3) permission for the user, w (2) for the group, and read, write, and execute for the users.
How to Change Directory Permissions in Linux for the Group Owners and Others
The command for changing directory permissions for group owners is similar, but add a “g” for group or “o” for users and “u” for owners:
To change directory permissions for everyone, use “u” for owners, “g” for group, “o” for users, and “ugo” or “a” (for all).
chmod ugo+rwx foldername to give read, write, and execute to everyone.
chmod a=r foldername to give only read permission for everyone.
As you can see, there are several options when it comes to permissions. You have the capability to dictate usability among users. While it may be easier to just give all permission to everyone, it may end up biting you in the end. So choose wisely.
Save the file, then to run open the terminal, and type ./hello_world.sh
PS: You might get permission denied error, due to hello_world.sh file not having execute permission for any users.
Use “chmod +x hello_world.sh” to provide execute permission.
This first line (#!/bin/bash or #!/bin/sh) has a name. It is known as ‘she-bang‘ (shabang). This derives from the concatenation of the tokens sharp (#) and bang (!).
It is also called as sh-bang, hash-bang, pound-bang or hash-pling. In computing, a she-bang is the character sequence consisting of the characters number sign and exclamation mark (#!) at the beginning of a script.
Here is how you can check disk usage in unix terminal.
Disk usage is a critical thing in servers, Certain times the web service or server acts weird and it could be disk space being full.
In order to check the disk space we can use “df” command in unix. which will show us the disk/file system, used and available disk quantity. also the mount location of the disk.
We have discussed below listed commands
df – disk usage checking
man – man is nothing but manual, by passing the command as parameter to this command will open the manual for the command in parameter.
aryanz_co_in@pop-os:~/dev/folder1$ touch hello.txt
aryanz_co_in@pop-os:~/dev/folder1$ vi hello.txt
[Edit the file] to save press Esc + :wq (w is for save and q is for quit)
aryanz_co_in@pop-os:~/dev/folder1$ cat hello.txt
Keep the learning short, not to waste your precious time.