![]() |
The operator `+' causes the permissions selected to be added to the existing permissions of each file; `-' causes them to be removed; and `=' causes them to be the only permissions that the file has. The letters `rwxXstugo' select the new permissions for the affected users: read (r), write (w), execute (or access for directories) (x),execute only if the file is a directory or already has execute permission for some user (X), set user or group ID on execution (s), save program text on swap device (t), the permissions that the user who owns the file currently has for it (u), the permissions that other users in the file's group have for it (g), and the permissions that other users not in the file's group have for it (o).
A numeric mode is from one to four octal digits (0-7), derived by adding up the bits with values 4, 2, and 1. Any omitted digits are assumed to be leading zeros. The first digit selects the set user ID (4) and set group ID (2) and save text image (1) attributes. The second digit selects permissions for the user who owns the file: read (4), write (2), and execute (1); the third selects permissions for other users in the file's group, with the same values; and the fourth for other users not in the file's group, with the same values. chmod never changes the permissions of symbolic links; the chmod system call cannot change their permissions. This is not a problem since the permissions of symbolic links are never used. However, for each symbolic link listed on the command line, chmod changes the permissions of the pointed-to file. In contrast, chmod ignores symbolic links encountered during recursive directory traversals.
$ ls -l
-rw-r-r- 1 root root 0 Mar 26 19:22 firstfile
-rw-r-r- 1 root root 0 Mar 26 19:22 fourfile
-rw-r-r- 1 root root 0 Mar 26 19:22 lastfile
-rw-r-r- 1 root root 0 Mar 26 19:22 onefile
-rw-r-r- 1 root root 0 Mar 26 19:22 thatfile
-rw-r-r- 1 root root 29 Mar 26 19:23 thisfile
-rw-r-r- 1 root root 0 Mar 26 19:22 thosefiles
-rw-r-r- 1 root root 0 Mar 26 19:22 threefile
-rw-r-r- 1 root root 0 Mar 26 19:22 twofile
$ chmod +x firstfile
-rwxr-xr-x 1 root root 0 Mar 26 19:22 firstfile*
$ chmod 444 fourfile
-r-r-r- 1 root root 0 Mar 26 19:22 fourfile
$ chmod 555 lastfile
-r-xr-xr-x 1 root root 0 Mar 26 19:22 lastfile*
$ chmod 666 onefile
-rw-rw-rw- 1 root root 0 Mar 26 19:22 onefile
$ chmod 777 thatfile
-rwxrwxrwx 1 root root 0 Mar 26 19:22 thatfile
$ chmod 400 thisfile
-r---- 1 root root 29 Mar 26 19:23 thisfile
$ chmod 500 thosefiles
-r-x--- 1 root root 0 Mar 26 19:22 thosefiles
$ chmod 600 threefile
-rw---- 1 root root 0 Mar 26 19:22 threefile
$ chmod 700 twofile
-rwx--- 1 root root 0 Mar 26 19:22 twofile*
$ chmod 1400 firstfile
-r----T 1 root root 0 Mar 26 19:22 firstfile
$ chmod 2400 fourfile
-r--S-- 1 root root 0 Mar 26 19:22 fourfile
$ chmod 3400 lastfile
-r--S-T 1 root root 0 Mar 26 19:22 lastfile