Skip to content

Archive for

How do i set linux file permissions using symbolic mode

If you want to set the file permissions in Linux, you can get a two options to set the appropriate permissions of files. One is Symbolic method and Numeric method. Here you can read about symbolic method examples.

The chmod (change mode) command will useful to change your file permissions. First of all I want to explain about how do i set appropriate file permissions for user, groups and others. Here others means Everybody (users) can able to view the files or ability to change the file contents if you give permissions.

The basically Linux file is 9 rightmost bits in 10bits permissions block.

Example :

rw-rw-rw- 1 root   root       889 Nov 10 10:59 1millions.txt

Which user :

u  --> user

g  --> groups

o  --> others

a   --> all

What to do ?

+   --> add this permission

-  --> remove this permission

= --> set exactly this permission

Which permissions :

r  --> read

w   --> write

x  ---> execute

Let’s see some examples :
Example 1: Set read write permission of this files for all

[root@siebelts u01]# chmod a=rw 1millions.txt

[root@siebelts u01]# ls -l 1millions.txt
-rw-rw-rw- 1 root root 889 Nov 10 10:59 1millions.txt

Example 2: Want to remove write permission for all users

[root@siebelts u01]# chmod a-w 1millions.txt
[root@siebelts u01]# ls -l 1millions.txt
-r--r--r-- 1 root root 889 Nov 10 10:59 1millions.txt
[root@siebelts u01]#

Example 3: Set the write permission for owner of this file

[root@siebelts u01]# chmod u+w 1millions.txt
[root@siebelts u01]# ls -l 1millions.txt
-rw-r--r-- 1 root root 889 Nov 10 10:59 1millions.txt

Example 4: set write and execute permission for groups

[root@siebelts u01]# chmod g+wx 1millions.txt
[root@siebelts u01]# ls -l 1millions.txt
-rw-rwxr-- 1 root root 889 Nov 10 10:59 1millions.txt
[root@siebelts u01]#

Example 5: set read and write  permission for other user also

[root@siebelts u01]# chmod o+rw 1millions.txt
[root@siebelts u01]# ls -l 1millions.txt
-rw-rwxrw- 1 root root 889 Nov 10 10:59 1millions.txt
[root@siebelts u01]#

Example 6 : remove the write, execute permission of  groups and others

[root@siebelts u01]# chmod g-rw 1millions.txt && chmod o-rw 1millions.txt
[root@siebelts u01]# ls -l 1millions.txt
-rw---x--- 1 root root 889 Nov 10 10:59 1millions.txt

Example 7: Let’s see i change the groups of this file and try to write on this file.

[root@siebelts u01]# chown :oinstall 1millions.txt
[root@siebelts u01]# ls -l 1millions.txt
-rw---x--- 1 root oinstall 889 Nov 10 10:59 1millions.txt
[root@siebelts u01]# su - oracle
[oracle@siebelts ~]$ vi /u01/1millions.txt

"/u01/1millions.txt" [Permission Denied]
[oracle@siebelts ~]$

Example 8: set write permission of this file and try to write using member of the oinstall group

[root@siebelts u01]# chmod g+rw 1millions.txt
[root@siebelts u01]# ls -l 1millions.txt
-rw-rw---- 1 root oinstall 32 Nov 11 04:25 1millions.txt

[root@siebelts u01]# cat 1millions.txt
File permission symbolic test
[root@siebelts u01]# su - oracle

[oracle@siebelts ~]$ cd /u01
[oracle@siebelts u01]$ vi 1millions.txt
[oracle@siebelts u01]$ cat 1millions.txt
File permission symbolic test
File can be write and read by member of oinstall
[oracle@siebelts u01]$

Reference : Tuxfiles Linux File permissions