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.
Change Files And Directory Permission Through Chmod Command
In Linux operating system file and directory permission can be changed through chmod command. Here is some of the example of chmod command.
sudo chmod 777 example.txt
The meaning of above command means i am assigning read, write and execute permission for owner,usergroup and other users.
Like rwx you can represent the permission numerically
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
means the file has
owner = read+write+execute permission
group = read+write
other = read