How to change file and directory permissions in linux using chmod command.
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 will learn how file permissions work and how you change file permissions using chmod command.
How to Copy Files and Directories in Ubuntu.
How to Change File, Directory Permissions in Linux
Before we start digging go to the terminal (shortcut ctrl+atl+T) and type ls -l .
1 |
# ls -l |
It displays list of files and folders and their permssion.
1 2 3 |
-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 Examples – Change Files & Directory Permission
In Linux operating system file and directory permission can be changed through chmod command. Let’s learn how it works.
1 2 3 |
/* Assign read,write,execute permission to example.txt file. */ # sudo chmod 777 example.txt |
This 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)
How to create new files using Touch command.
Another example
1 |
# sudo chmod 764 test1.txt |
Using this command we gave following permissions.
owner = read+write+execute permission
group = read+write
other = read
How to Remove Package through Ubuntu Terminal Command.
Apply read,write,execute permission to all files under directory.
1 |
# sudo chmod -R 777 directory-name/ |
To learn more about chmod command you can take the help of ubuntu manual. Just go to terminal and type
1 |
# man chmod |