chmod(1)
Change file and directory permissions using symbolic or octal notation.
Synopsis
chmod [OPTION]... MODE[,MODE]... FILE...Description
chmod modifies file and directory permissions. Permissions control who can read (r), write (w), and execute (x) files. You can use symbolic mode (u/g/o/a +/-/= rwx) or octal mode (0-7 for each digit representing user/group/other).
Octal notation: first digit is user, second is group, third is others. Each digit is calculated as: read=4, write=2, execute=1. For example, 755 means rwxr-xr-x (user has all permissions, group and others can read and execute).
Symbolic notation uses: u (user), g (group), o (others), a (all); + (add), - (remove), = (set exactly); r (read), w (write), x (execute).
Common options
| Flag | What it does |
|---|---|
-R, --recursive | Change permissions recursively for directories and their contents |
-v, --verbose | Print a diagnostic message for every file processed |
-c, --changes | Print a message only for files whose permissions actually change |
-f, --silent, --quiet | Suppress error messages |
--reference=FILE | Change permissions to match those of the reference FILE |
-h, --no-dereference | Affect symbolic links instead of their targets (on systems that support this) |
Examples
Set file.txt to rw-r--r-- (user reads/writes, group and others read only)
chmod 644 file.txtMake script.sh executable: rwxr-xr-x (common for scripts and binaries)
chmod 755 script.shAdd execute permission for the user only (symbolic notation)
chmod u+x script.shRecursively set all files and subdirectories in mydir/ to rwxr-xr-x
chmod -R 755 mydir/Remove write permission for the group (symbolic notation)
chmod g-w file.txtRemove execute permission from all (user, group, others)
chmod a-x script.shSet secret.key to rw------- (user reads/writes, group and others have no access)
chmod 600 secret.keySet exact permissions: user rwx, group rx, others nothing (symbolic)
chmod u=rwx,g=rx,o= myfile