The chmod command changes file and directory permissions in Unix/Linux.
| Symbol | Meaning |
|---|---|
u | User (owner) |
g | Group |
o | Others |
a | All (u+g+o) |
| Symbol | Meaning | Numeric |
|---|---|---|
r | Read | 4 |
w | Write | 2 |
x | Execute | 1 |
Use +, -, or = to modify permissions:
chmod u+x file # Add execute to user
chmod go-w file # Remove write from group and others
chmod a=r file # Set read-only for all
Combine values for user, group, and others:
| Mode | Permissions | Meaning |
|---|---|---|
| 777 | rwxrwxrwx | Full access |
| 755 | rwxr-xr-x | Common for scripts |
| 644 | rw-r–r– | Common for text files |
chmod 755 script.sh
chmod 644 notes.txt
These flags go beyond basic read/write/execute and control execution context and deletion behavior.
setuid (Set User ID on Execution)4passwd need elevated privileges to modify system files.chmod 4755 /usr/bin/somebinary
# -rwsr-xr-x → 's' replaces 'x' in user field
⚠️ Security risk if misused — avoid setting on scripts or user-controlled binaries.
setgid (Set Group ID)2chmod 2755 /shared/folder
# drwxr-sr-x → 's' in group field
📁 On directories, this ensures group consistency for collaborative environments.
sticky Bit1/tmp directory — prevents users from deleting each other’s files.chmod 1777 /tmp
# drwxrwxrwt → 't' in others field
🧷 Think of it as a “delete lock” for shared spaces.
x) Flag: Files vs Directories| Context | Effect of x Permission |
|---|---|
| File | Allows execution as a program/script |
| Directory | Allows entering the directory (cd) and accessing contents by name |
| Permission | Can List (ls) | Can Enter (cd) | Can Access Files |
|---|---|---|---|
r | ✅ | ❌ | ✅ (if name known) |
x | ❌ | ✅ | ✅ (if name known) |
r+x | ✅ | ✅ | ✅ |
🧠 Without
xon a directory, you can’tcdinto it — even if you can list its contents.
| Command | Description |
|---|---|
chmod +x file | Make file executable |
chmod -R 755 dir | Recursively set permissions |
chmod u=rwx file | Set user to rwx only |
chmod a-x file | Remove execute from all |
💡 Tip: Use ls -l to view current permissions.




















