Linux chmod Command Clearly Explained
The users can be categorized into user, group and others.
Users generally need permissions to either a file or a directory.
Base on weather it is a file or directory, the permissions are shown below. The 3 most common permissions are,
If it is a directory,
If it is a file,
To provide a user with a permission or access the chmod command can be used.
chmod -[Options] [Mode] [file | directory]
R – This option tells the chmod command to change the permissions to all the subdirectories recursively if the specified target is a directory.
There are two ways in which we can specify the permissions,
In the symbolic way, there are set of mnemonics identifier with which we can set to whom the permissions are to be set.
Then there are operators that we can use to assign the various permissions that we discussed already(r, w, x).
To specify multiple users at the same time use , to separate them and no space must be included. See the example for the = shown above.
Octal representation is used to set the permissions for all the users at the same time using the octal equivalent code. The following table shows the various way by which you can specify the permissions.
|4 (r – read)||2 (w – write)||1 (r – execute)||Permissions set|
|0||0||1||Will set the execute permission for the file/directory.|
|0||2||0||Will set the write permission for the file/directory.|
|4||0||1||1 + 4 = 5, so 5 Will set the read and execute permission for the file/directory.|
|4||2||1||1 + 2 + 4 = 7, so 7 Will set the read, write and execute permission for the file/directory.|
By using the above way to set permissions, we must set the permissions for all users, groups and others at the same time.
To use the recursive method use the R option.