≡ Menu

UNIX / Linux: Explain The Nine Permissions Bits On Files

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
Sample outputs:

-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:

  1. - Regular file.
  2. b Block special file (stored in /dev).
  3. c Character special file (stored in /dev).
  4. d Directory.
  5. l Symbolic link.
  6. p FIFO.
  7. s Socket.
  8. w Whiteout.

Examples

Show directory type with the ls command:
ls -ld /etc
Sample outputs:

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
Sample outputs:

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:

  1. r : The file is readable; if - it is not readable.
  2. w : the file is writable; if -, it is not writable.
  3. 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.
  4. 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.
  5. x : The file is executable or the directory is searchable.
  6. - : 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.

  1. T The sticky bit is set (mode 1000), but not execute or search permission.
  2. t The sticky bit is set (mode 1000), and is searchable or executable.

References:

  • ls command man page
Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 1 comment… add one }

  • Dinesh February 10, 2011, 7:43 am

    It understands very well.

    Could you please elaborate about small t and big T and same for small s and big S?

Leave a Comment