Showing posts with label Directory or File Permission in Linux. Show all posts
Showing posts with label Directory or File Permission in Linux. Show all posts

Tuesday 15 December 2015

Directory or File Permission in Linux

For Example---

[oracle@sbldb2 ~]$ ll
total 516
-rw-r--r-- 1 oracle oinstall 235340 Nov  2 11:50 02112015.lst
-rw-r--r-- 1 oracle oinstall 257702 Sep  8  2014 awrrpt_1_7407_7409.txt
drwxr-xr-x 2 oracle oinstall   4096 Mar 12  2014 Desktop
-rw-r--r-- 1 oracle oinstall    364 Apr  1  2014 Dhaka.bkp
drwxr-xr-x 3 oracle oinstall   4096 Mar 23  2014 oradiag_oracle
drwxr-xr-x 4 oracle oinstall   4096 Sep  2 15:45 rman
-rw-r--r-- 1 oracle oinstall   3965 Jan  5  2015 tuning.sql

Total 10 fields in prefix of every files and directory as above

Here
user ---> oracle
group ---> oinstall

-rwxr-xr-x

1st filed represents ---> Directory
2nd,3rd and 4th filed represent ---> Owner Permission
5th,6th and 7th filed represent ---> Group Member Permission
8th,9th and 10th field represent ---> Other Permission

You can setup following mode on each files. In a Linux and UNIX set of permissions is called as mode:

Read (r)
Write (w)
Execute (x)

Linux Read mode permissions

--Read access on a file allows you to view file
--Read access on a directory allows you to view directory contents with ls command
Write mode permissions

--Write access on a file allows you to write to file
--Write access on a directory allows you to remove or add new files
Execute mode permissions

--Execute access on a file allows to run program or script
--Execute access on a directory allows you access file in the directory

Octal numbers and permissions

You can use octal number to represent mode/permission:
r: 4
w: 2
x: 1

Use above method to calculate permission for group and others. Let us say you wish to give full permission to owner, read & execute permission to group, and read only permission to others, then you need to calculate permission as follows:

-rwx-rw--x-- 1 oracle oinstall   3965 Jan  5  2015 tuning.sql

User (oracle) = r+w+x = 4+2+1 = 7
Group (oinstall) = r+w = 4+2+0 = 6
Others = r= 4+0+0 = 4

Effective permission is 764.