Numerical Representation of Permissions
The chmod command (CHange MODe) is used to modify file and directory permissions. The simplest way to use chmod is via Octal (numeric) notation.
Each permission (r, w, x) is assigned a numeric value:
| Permission | Numeric Value |
|---|---|
| r (Read) | 4 |
| w (Write) | 2 |
| x (Execute) | 1 |
| - (No permission) | 0 |
Calculating the Octal Code
The total permission for each set (User, Group, Others) is the sum of its values. A standard permission code is a three-digit number.
| Permissions | Sum | Octal Code |
|---|---|---|
rwx (Read, Write, Execute) | 4 + 2 + 1 | 7 |
rw- (Read, Write) | 4 + 2 + 0 | 6 |
r-x (Read, Execute) | 4 + 0 + 1 | 5 |
r-- (Read only) | 4 + 0 + 0 | 4 |
Example: chmod 754
- 7 (User): rwx
- 5 (Group): r-x
- 4 (Others): r--
bash
Gives the owner full access, the group read/execute, and others read only.
$ chmod 754 my_script.sh