Page 162 - DCAP106_OPERATING_SYSTEM_TOOLS
P. 162
Unit 9: The File System
z z the members of the owning group (portage) also have read, write and execute rights Notes
z z everybody else can’t do anything (no read, no execute and certainly no write rights)
Another method to obtain the access rights is to use the stat command.
Example:
$ stat /etc/passwd
File: `/etc/passwd’
Size: 3678 Blocks: 8 IO Block: 4096 regular file
Device: 808h/2056d Inode: 3984335 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2013-03-18 21:46:06.000000000 +0100
Modify: 2013-03-18 21:46:06.000000000 +0100
Change: 2013-03-18 21:46:06.000000000 +0100
In the output of the stat command, you notice the same access flags as we identified before (-rw-
r--r-- in this case), but also a number. This number identifies the same rights in a mort short-hand
notation.
To be able to read the number, you need to know the values of each right:
z z execute rights gets the number 1
z z write rights gets the number 2
z z read rights gets the number 4
To get the access rights of a particular group, add the numbers together.
For a file with privileges (-rw-r--r--), this gives the number 644:
z z 6 = 4 + 2, meaning read and write rights for the owner
z z 4 = 4, meaning read rights for the group
z z 4 = 4, meaning read rights for everybody else
The first 0 that we notice in stats’ output identifies the file as having no very specific privileges.
There are a few specific privileges inside Linux as well.
The restricted deletion flag, or sticky bit, has been identified before. When set on a directory, it
prevents people with write access to the directory, but not to the file, to delete the file (by default,
write access to a directory means that you can delete files inside that directory regardless of their
ownership). The most well-known use for this flag is for the /tmp location:
Example:
$ stat /tmp
File: `/tmp’
Size: 28672 Blocks: 56 IO Block: 4096 directory
Device: 808h/2056d Inode: 3096577 Links: 759
Access: (1777/drwxrwxrwt) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2010-01-10 17:44:04.000000000 +0100
Modify: 2013-04-02 00:04:36.000000000 +0200
Change: 2013-04-02 00:04:36.000000000 +0200
LOVELY PROFESSIONAL UNIVERSITY 155