In Linux operating system everything is a file , if it is not a file then it’s a process so everything has default permission assigned. File permission defines which file has read,write,execute permission and for which user group.In this article you learn how file permission work and how you change the file permission using chmod command.
Linux/Ubuntu File Permission
Before we going to start, go to the terminal (shortcut ctrl+atl+T) and type ls -l .
It shows output like this
-rw-rw-r-- 1 raj raj 17202 Feb 28 15:26 abc.php
-rw------- 1 raj raj 5768 Feb 20 11:48 exam.tpl
drwxrwxrwx 5 raj raj 4096 Mar 7 07:37 Desktop
So start from first column what rwx indicates.
r – stands for read permission
w – stands for write permission
x – stands for execute permission
-(dash) – represents no permission is assigned
Beginning of three letter indicates owner permission, then group and next three for anyone else.
Chmod Command – Change Files And Directory Permission
In Linux operating system file and directory permission can be changed through chmod command. Here is some of the example of chmod command.
/* Assign read,write,execute permission to example.txt file. */
# sudo chmod 777 example.txt
Above command assigns read, write and execute permission to owner,usergroup and other users.
Numeric representation of read,write and execute permission.
4 – read
2 – write
1 – execute
Combination of permission
0 – no permission, this person cannot read, write or execute
1 – execute only
2 – write only
3 – execute and write only (1 + 2)
4 – read only
5 – execute and read only (1 + 4)
6 – write and read only (2 + 4)
7 – execute, write and read (1 + 2 + 3)
# sudo chmod 764 test1.txt
Using above command we have give following permissions.
owner = read+write+execute permission
group = read+write
other = read
Apply read,write,execute permission to all files under directory recursively
# sudo chmod -R 777 directory-name/
To learn more about chmod command you take the help of ubuntu manual. Just go to terminal and type
# man chmod