Custom Search

Monday, March 25, 2013

How to understand and set file permissions on Linux

$ ls -l
drwx------  3 saju saju   4096 Mar 25 12:37 appliance_store
-rw-rw-r--  1 saju saju 223253 Mar 25 15:47 squid.log

The very first column, shows the file type and permissions.The second column shows the number of links (directory entries that refer to the file), the third one shows the owner of the file, and the fourth one shows the group the file belongs to. The other columns show the file's size in bytes, date and time of last modification, and the file name.

The first column, is organized into four separate groups.
The first group consists of only one character, and it shows the file's type.
For example, The first character can be any of these:

d = directory
- = regular file
l = symbolic link
s = Unix domain socket
p = named pipe
c = character device file
b = block device file

The next nine characters show the file's permissions, divided into three groups, each consisting of three characters. The first group of three characters shows the read, write, and execute permissions for user, the owner of the file. The next group shows the read, write, and execute permissions for the group of the file. Similarly, the last group of three characters shows the permissions for other, everyone else. In each group, the first character means the read permission, the second one write permission, and the third one execute permission.

The characters are pretty easy to remember.

r = read permission
w = write permission
x = execute permission
- = no permission


How to set file permissions - symbolic mode
===============================


Which user?
u     user/owner
g     group
o     other
a     all


What to do?
+     add this permission
-     remove this permission
=     set exactly this permission


Which permissions?
r     read
w     write
x     execute


How to set file permissions - numeric mode
===============================


4 = read (r)
2 = write (w)
1 = execute (x)
0 = no permission (-)


Which number?
0     ---
1     --x
2     -w-
3     -wx
4     r--
5     r-x
6     rw-
7     rwx

No comments:

Post a Comment