In the Linux environment not all the users have permission to modify files and have access to directories. There are a set of user access permissions based on which category the user belong (user, group or other users). A superuser is the one who has access to the entire system whereas a normal users only have a particular set of permission and access to files and directories. If a normal user wishes to do something with a file to which he does not have appropriate permissions, that is where the “chmod" command comes in.
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).
= - Sets the permission provided and the other permissions are denied.
+ - Sets the provided permissions and the other permissions are unchanged.
- - Removes the provided permissions and the others are left unchanged.
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.
I'm Tamil Selvan, a Passionate Programmer, Web Designer/Developer, Blogger and Gamer. I love Designing and Creating new things that helps and inspires users. Living in Chennai, India.