$linuxjunkies
>

chmod(1)

Change file and directory permissions using symbolic or octal notation.

UbuntuDebianFedoraArch

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

FlagWhat it does
-R, --recursiveChange permissions recursively for directories and their contents
-v, --verbosePrint a diagnostic message for every file processed
-c, --changesPrint a message only for files whose permissions actually change
-f, --silent, --quietSuppress error messages
--reference=FILEChange permissions to match those of the reference FILE
-h, --no-dereferenceAffect 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.txt

Make script.sh executable: rwxr-xr-x (common for scripts and binaries)

chmod 755 script.sh

Add execute permission for the user only (symbolic notation)

chmod u+x script.sh

Recursively 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.txt

Remove execute permission from all (user, group, others)

chmod a-x script.sh

Set secret.key to rw------- (user reads/writes, group and others have no access)

chmod 600 secret.key

Set exact permissions: user rwx, group rx, others nothing (symbolic)

chmod u=rwx,g=rx,o= myfile

Related commands