UNDERSTANDING UNIX FILE PERMISSIONS

Unix file permissions are always recorded as THREE numeric numbers. Each of these numbers represent different class of users. These 3 user classes are,
a) Owner b) Member of the same UNIX group as file owner c) All OTHER UNIX users

If a file has permission 755 means Owner has READ/WRITE/EXECUTE , Group users have READ/EXECUTE and OTHERS have READ/EXECUTE permission.

Permission Value    Meaning
4         =>                   Read
2         =>                   Write
1         =>                   Execute

rwx   => 4+2+1=7
rw-    => 4+2+0=6
r-x     => 4+0+1=5
r--      => 4+0+9=4

Lets explain it with highlighted file below.

[oracle@usha ~]$ ls -l
total 264
-rw-r--r--. 1 oracle oinstall 57311 Feb  2 21:46 dbaviews.txt
drwxr-xr-x. 2 oracle oinstall  4096 Feb  1 19:18 Desktop

-  => Ignore the first dash. It represents file type.  d in this location represents directory.
rw- => The first group of three character rw- => 4+2+0=6 means owner has READ/WRITE permission
r--  => The next group of three character r-- =>4+0+0=4 means Groups have READ permission.
r--  => The last group of three character r-- =>4+0+0=4 means Others have READ permission.

[oracle@usha ~]$

FIND the system wide default file permission:

[oracle@usha ~]$ umask
0022
[oracle@usha ~]$ umask 000
[oracle@usha ~]$ touch temp
[oracle@usha ~]$ ls -al temp
-rw-rw-rw-. 1 oracle oinstall 0 Feb  5 03:09 temp

If you do the math you will see here the default system wide permission is 666.

Reset the umask to original value.
[oracle@usha ~]$ umask
0000
[oracle@usha ~]$ umask 0022
[oracle@usha ~]$

The effect of UMASK settings

[oracle@usha ~]$ umask 0022
[oracle@usha ~]$ touch a.txt
[oracle@usha ~]$ ls -al a.txt
-rw-r--r--. 1 oracle oinstall 0 Feb  5 03:16 a.txt
[oracle@usha ~]$

Server Default :                      6 6 6
Umask value :                       0 2 2
New file permission:               6 4 4



Comments