Although the syntax of the command varies somewhat by implementation, it generally accepts either a single octal value (which specifies all the mode bits on each file), or a comma-delimited list of symbolic specifiers (which describes how to change the existing mode bits of each file). The remaining arguments are a list of paths to files to be modified.7
Changing permissions is only allowed for the superuser (root) and the owner of a file.
If a symbolic link is specified, the target of the link has its mode bits adjusted. Permissions directly associated with a symbolic link file system entry are typically not used.
Optional, command-line options may include:
Given a numeric permissions argument, the chmod command treats it as an octal number, and replaces all the mode bits for each file. (Although 4 digits are specified, leading 0 digits can be elided.)8
Why octal rather than decimal? 9
There are twelve standard mode bits, comprising 3 special bits (setuid, setgid, and sticky), and 3 permission groups (controlling access by user, group, and other) of 3 bits each (read, write, and exec/scan); each permission bit grants access if set (1) or denies access if clear (0).
As an octal digit represents a 3-bit value, the twelve mode bits can be represented as four octal digits. chmod accepts up to four digits and uses 0 for left digits not specified (as is normal for numeric representation). In practice, 3 digits are commonly specified since the special modes are rarely used and the user class is usually specified.
In the context of an octal digit, each operation bit represents a numeric value: read: 4, write: 2 and execute: 1. The following table relates octal digit values to a class operations value.
The command stat can report a file's permissions as octal. For example:
The reported value, 754 indicates the following permissions:
A code permits execution if and only if it is odd (i.e. 1, 3, 5, or 7). A code permits read if and only if it is greater than or equal to 4 (i.e. 4, 5, 6, or 7). A code permits write if and only if it is 2, 3, 6, or 7.
The chmod command accepts symbolic notation that specifies how to modify the existing permissions.10 The command accepts a comma-separate list of specifiers like: [classes]+|-|=operations
Classes map permissions to users. A change specifier can select one class by including its symbol, multiple by including each class's symbol with no delimiter or if not specified, then all classes are selected and further the bits of umask mask will be unchanged.11 Class specifiers include:
As ownership is key to access control, and since the symbolic specification uses the abbreviation o, some incorrectly think that it means owner, when, in fact, it is short for others.
The change operators include:
Operations can be specified as follows:
Most chmod implementations support the specification of the special modes in octal, but some do not which requires using the symbolic notation.
The ls command can report file permissions in a symbolic notation that is similar to the notation used with chmod. ls -l reports permissions in a notation that consists of 10 letters. The first indicates the type of the file system entry, such as dash for regular file and 'd' for directory. Following that are three sets of three letters that indicate read, write and execute permissions grouped by user, group and others classes. Each position is either dash to indicate lack of permission or the single-letter abbreviation for the permission to indicate that it's granted. For example:
The permission specifier -rwxr-xr-- starts with a dash which indicates that findPhoneNumbers.sh is a regular file; not a directory. The next three letters rwx indicate that the file can be read, written, and executed by the owning user dgerman. The next three letters r-x indicate that the file can be read and executed by members of the staff group. And the last three letters r-- indicate that the file is read-only for other users.
Add write permission to the group class of a directory, allowing users in the same group to add files:
Remove write permission for all classes, preventing anyone from writing to the file:
Set the permissions for the user and group classes to read and execute only; no write permission; preventing anyone from adding files:
Enable write for the user class while making it read-only for group and others:
To recursively set access for the directory docs/ and its contained files:
chmod -R u+w docs/
To set user and group for read and write only and set others for read only:
chmod 664 file
To set user for read, write, and execute only and group and others for read only:
chmod 744 file
To set the sticky bit in addition to user, group and others permissions:
chmod 1755 file
To set UID in addition to user, group and others permissions:
chmod 4755 file
To set GID in addition to user, group and others permissions:
chmod 2755 file
The modes/permissions are shown when listing files in long format. /wiki/Ls ↩
"Tutorial for chmod". catcode.com. http://catcode.com/teachmod/ ↩
"Native Win32 ports of some GNU utilities". unxutils.sourceforge.net. http://unxutils.sourceforge.net/ ↩
IBM. "IBM System i Version 7.2 Programming Qshell" (PDF). IBM. Retrieved 5 September 2020. /wiki/IBM ↩
"AIX 5.3 System management". IBM knowledge Center. IBM. Retrieved 30 August 2015. http://www-01.ibm.com/support/knowledgecenter/#!/ssw_aix_53/com.ibm.aix.baseadmn/doc/baseadmndita/acl.htm?cp=ssw_aix_53 ↩
"chmod(1): change file mode bits - Linux man page". linux.die.net. https://linux.die.net/man/1/chmod ↩
"chmod Man Page with examples and calculator - Linux - SS64.com". ss64.com. (note that "space delimited" is a feature of the shell, not of chmod itself.) https://ss64.com/bash/chmod.html ↩
This differs from the “C” language, where the 0 prefix for octal numbers is a remnant of its early period. ↩
Although rarely used today, during the early development of UNIX, octal was very useful because repeating groups of 3 bits were common in the physical structure of computers at the time, and these bits were easier to read & understand when encoded as octal digits, just as groups of 4 bits are easier when grouped into hexadecimal digits. The numeric expression of filesystem permissions in octal is one of the few of the few remnants of this time. ↩
"AIX 5.5 Commands Reference". IBM Knowledge Center. IBM. Retrieved 30 August 2015. http://www-01.ibm.com/support/knowledgecenter/#!/ssw_aix_53/com.ibm.aix.cmds/doc/aixcmds1/chmod.htm?cp=ssw_aix_53%2F1-2-0-2-78 ↩
"Permissions masking with umask, chmod, 777 octal permissions". teaching.idallen.com. http://teaching.idallen.com/cst8207/19w/notes/510_umask.html ↩