chmod - Used for changing the permission of files and folders.
Syntax:
chmod [options] [permissions] <file name or folder name>
Description:
Permissions can be changed with options -r, -w, -x and also by numeric.
Before doing any change we can see the current permissions of files or directories using ls command.
"ls -l" displays the files and folders vertically with permissions as
-rwxrw-r-- 4 root n500 5024 2013-11-11 foo.txt
Here -rwxrw-r-- explains the permission of foo.txt file
It has 10 characters in it.
First, -/d : For files it will display dash and for folders it will display d
Next 3, rwx : Permission of owner ( r - read, w - write, x - execute )
Next 3, rw- : Permission of group. Only read and write permission is there.
Next 3, r-- : Others. Only read access is there. Others who does not belong to group n500 can only read the file.
Numeric permission are 4 for read, 3 for write and 1 for execution. It will be specified in three digits for owners, group and others.
Lets see how to change the permissions as mentioned below:
| Permissions | Descriptions |
|---|---|
| chmod 700 | Read, write and execute permission is given to owner |
| chmod 730 | Read permission is given to group and all permissions to owner |
| chmod 733 | All permissions to owner and read permissions to group and others |
| chmod 763 | Read and write permission is given to group, read to others, all to owner |
| chmod 773 | All permissions given to owner and group, read to others |
| chmod 776 | All permissions given to owner, group and others except execute for given to others |
| chmod 777 | All permission given to owner, group and others |
Examples:
Let us see how to give permissions to folder named foo
chmod 700 foo
All permission 7 ( 4 + 3 + 1 ) is given only to owner.
chmod 730 foo
Group is also given read permission.
chmod 733 foo
Read permission is given for others also.
chmod 763 foo
Write permission is given for group.
chmod 773 foo
All permissions are given for owner and group but others has only read permission
chmod 776 foo
All permissions given to owner and group but others are not given execute permission.
chmod 777 foo
All permissions given to owner, group and others.
chmod -R 777 foo
Apart from all permissions to owner, group and others for the folder foo, contents inside folder foo are also given with same permissions.
Similarly permissions can be given to files also.
chmod 777 foo.txt
R is not required since file will not contain files and folders inside it.
chmod 777 /home/abc
Permissions are given to folder named foo present inside the home directory.