Can you completely explain the nine permissions bits on UNIX or Linux files?
Each file in UNIX or Linux has the nine permission bits as follows:
ls -l /etc/hosts
-rw-r--r-- 1 root root 401 2009-12-20 12:08 /etc/hosts
The Entry Type
There are total 10 bits -rw-r–r–:
The file mode printed under the -l option consists of the entry type (1st bit) and the permissions (9 bits). The entry type character describes the type of file, as follows:
- – Regular file.
- b Block special file (stored in /dev).
- c Character special file (stored in /dev).
- d Directory.
- l Symbolic link.
- p FIFO.
- s Socket.
- w Whiteout.
Show directory type with the ls command:
ls -ld /etc
drwxr-xr-x 170 root root 12288 2010-02-24 11:39 /etc
Show block device type (hard disk) with the ls command:
ls -l /dev/sda
brw-rw---- 1 root disk 8, 0 2010-02-24 11:32 /dev/sda
The Permissions Bits
The next three fields are three characters each for
- File owner permissions
- File group permissions
- Other permissions (not part of both owner or group)
Each field has three character positions as follows:
- r : The file is readable; if – it is not readable.
- w : the file is writable; if -, it is not writable.
- S : If in the owner permissions, the file is not executable and set-user-ID mode is set. If in the group permissions, the file is not executable and set-group-ID mode is set.
- s : If in the owner permissions, the file is executable and set-user-ID mode is set. If in the group permissions, the file is executable and set group-ID mode is set.
- x : The file is executable or the directory is searchable.
- – : The file is neither readable, writable, executable, nor set-user-ID nor set-group-ID mode, nor sticky.
These next two apply only to the third character in the other permissions.
- T The sticky bit is set (mode 1000), but not execute or search permission.
- t The sticky bit is set (mode 1000), and is searchable or executable.
- ls command man page