File permissions in Unix-like systems control who can read, write, or execute a file or directory. They are shown using ls -l
.
Browse / chmod Command Cheatsheet
chmod Command Cheatsheet
A concise reference for the Linux/Unix chmod command, covering file permissions, symbolic and numeric modes, special permissions, and practical examples.
File Permissions & Basics
Understanding File Permissions
|
Permissions are set for three categories:
|
The permissions themselves are:
|
Directory execute ( |
Permissions are displayed as a 10-character string:
|
|
Symbolic Mode Syntax
Who |
Target user(s):
|
Operator |
Action:
|
Permissions |
Permission type:
|
Format |
Combine multiple changes with commas: |
Examples |
|
Recursive |
Use |
Symbolic & Numeric Modes
Symbolic Mode Examples
Make owner executable |
|
Remove write for group/others |
|
Set owner to rwx, group/others to r-x |
(Equivalent to |
Add read for all |
|
Remove execute from all |
|
Add read/write for group |
|
Recursively make scripts executable for owner |
|
Set permissions to owner rwx, group r-, others - |
(Equivalent to |
Numeric Mode (Octal)
Permissions can be represented as a 3-digit octal number. Each digit corresponds to the permissions for owner, group, and others, respectively. |
||||||||||||||||
Each permission has a numeric value:
|
||||||||||||||||
Sum the values for each permission type to get the digit for that category (Owner, Group, Others).
|
||||||||||||||||
Example:
Numeric mode: |
||||||||||||||||
The command format is:
Where NNN is the 3-digit octal number. |
||||||||||||||||
Numeric mode is often quicker for setting exact permission sets. |
Numeric Mode & Special Bits
Numeric Mode Examples
Owner rwx, Group rwx, Others rwx |
(Caution: Generally avoid unless necessary!) |
Owner rwx, Group r-x, Others r-x |
(Common for directories) |
Owner rw-, Group r--, Others r-- |
(Common for regular files) |
Owner rwx, Group ---, Others --- |
(Only owner can read/write/execute) |
Owner rw-, Group rw-, Others rw- |
(All can read/write, no execute. Caution advised.) |
Owner r--, Group r--, Others r-- |
(All can read, no write/execute) |
Special Permissions (SetUID, SetGID, Sticky)
Special permissions add capabilities beyond basic rwx. They are represented by a leading digit in numeric mode (4-digit octal) or special characters in symbolic mode ( |
SetUID (SUID): (4000)
|
SetGID (SGID): (2000)
|
Sticky Bit: (1000)
|
Special permissions are often used for security or group collaboration. Use with caution, especially SetUID/SetGID on files. |
Advanced Usage & Tips
Useful chmod Options
-R |
Recursively change permissions of directories and their contents.
|
-v, --verbose |
Output a diagnostic for every file processed.
|
-c, --changes |
Like verbose but only report when a change is made.
|
-f, --silent, --quiet |
Suppress most error messages. |
--reference=RFILE |
Use permissions from RFILE instead of specifying mode.
|
a+X |
Special mode: Grant execute (
|
Tips, Tricks, and Best Practices
Default Permissions ( New files/directories get default permissions based on the system’s Example: |
Files vs. Directories:
|
Common Settings:
|
Be Cautious with Granting write permission to ‘others’ ( |
Use
|
Test First: Especially when using |
Documentation: For full details and advanced options, consult the manual page:
|