CHMOD
The chmod command is used to change file and directory permissions in Linux and Unix-based systems. Permissions can be specified using either numeric (octal) or symbolic (letter) notation.
Numeric (Octal) Notation
Each permission is represented by a number:
4 = Read (r) 2 = Write (w) 1 = Execute (x)
The values are added together for each user category:
Owner Group Others
Example: chmod 755 script.sh
This results in:
Owner: rwx (7 = 4+2+1) Group: r-x (5 = 4+1) Others: r-x (5 = 4+1)
Symbolic (Letter) Notation
Permissions can also be modified using letters:
u = User (owner) g = Group o = Others a = All users
Operators:
+ = Add permission - = Remove permission = = Set exact permission
Examples:
chmod u+x script.sh # Add execute permission for the owner chmod g-w file.txt # Remove write permission from the group chmod a=r file.txt # Set read-only permission for everyone
Both notations achieve the same result. Numeric notation is commonly used for setting complete permission sets, while symbolic notation is useful for modifying specific permissions.
Special Bits
| Bit | Octal | Letter | on file | on directory |
|---|---|---|---|---|
| Setuid | 4 | u+s | program runs with uid of file | --- |
| Setgid | 2 | g+s | program runs with gid of file | directory passes group of directory to new files/directories beneath |
| Sticky | 1 | +t | --- | the files within the directory are only deletable and renamable from owner of directory or file |
example:
3770 Setgid + Sticky-Bit + rwx for user, rwx for group and none for other
