OSETC TECH

Linux/Unix: How To Use Chmod Command To Change File Permissions

As a new linux admin, you should know that there are three basic permission mode to files and directories, those are : read(r), write(w), execute(x).. also there are three permission roles for each files : user(u), group(g), o(other). it means that file permission defines the permissions for the owner of the file(user), members of the group who owns the file(group), and anyone else(others), each permission roles have different permission mode or combination permisison mode(rx,rwx…).

The syntax is:

chmod [options] permissions filename

chmod u+x filename

chomd o+wx filename

chomod g=rwx filename

Linux Change File Permission

let’s give you some chmod command examples in linux/unix operating system, see follows:

If you want add permission or change user permission to a file, you will use “+”,”-“,”=” symbols, “+” sysmbol means that adding permisson mode to user , group or others. “-” means remove permission and “=” means setting the permission you given.

1. Give user role executable permission to file ddd.txt

Issue the following command:

chmod  u+x ddd.txt

See Output:

[root@localhost osetc]# ls -l ddd.txt 

-rw-r--r-- 1 mtest mtest 0 12-13 20:14 ddd.txt

[root@localhost osetc]# chmod u+x ddd.txt 

[root@localhost osetc]# ls -l ddd.txt 

-rwxr--r-- 1 mtest mtest 0 12-13 20:14 ddd.txt

2. set the permission of ddd.txt to “owner can read and write, group can read only; others can read only”, it measn that owner need to set persmission to “rw”, group set to “r”,  others set “r”, issue the following command:

chmod u=rw,g=r,o=r ddd.txt

See Output:

[root@localhost osetc]# chmod u=rw,g=r,o=r ddd.txt

[root@localhost osetc]# ls -l ddd.txt 

-rw-r--r-- 1 mtest mtest 0 12-13 20:14 ddd.txt

3. Remove permission from a file

you know “-“symbol will be used to remove file permission from a file ,issue the following comand:

chmod u-w ddd.txt

Output:

[root@localhost osetc]# chmod u-w ddd.txt 

[root@localhost osetc]# ls -l ddd.txt 

-r--r--r-- 1 mtest mtest 0 12-13 20:14 ddd.txt

See Also: man chmod