Getting started

Introduction

chmod changes read, write, and execute permissions on files and directories. Modes use symbolic letters or octal digits.

Symbolic mode

$ chmod u+x script.sh
$ stat -c '%A %a' script.sh
-rwxr--r-- 744

u, g, o, and a select who to change; +, -, and = add, remove, or set exact bits. The example starts from mode 644.

See: Symbolic modes

Octal mode

$ chmod 640 secrets.txt
$ stat -c '%A %a' secrets.txt
-rw-r----- 640

Each digit sets read (4), write (2), and execute (1) for one of owner, group, and others.

See: Numeric modes

Directory access

$ chmod 755 public/
$ stat -c '%A %a' public/
drwxr-xr-x 755

On a directory, r lists names, w creates and removes entries, and x allows traversing it.

See: File permissions

Common changes

Add execute

$ chmod +x script.sh
$ stat -c '%A %a' script.sh
-rwxr-xr-- 754

With no class, + respects the umask (0027 here). Use a+x to give execute to everyone.

See: Setting permissions

Remove write

$ chmod go-w report.txt

- clears only the named bits and leaves the rest of the mode untouched.

See: Setting permissions

Set exact bits

$ chmod u=rw file.txt

= replaces that class's bits; chmod 644 file.txt does the same for all three classes.

See: Setting permissions

Apply recursively

$ chmod -R go-w \
    public/

-R applies the change to a whole tree. GNU chmod leaves symlinks alone.

See: chmod invocation

Reference file

$ chmod --reference=template.txt \
    target.txt

Copies the exact mode of another file; this option is GNU-specific.

See: Copying permissions

Inspect modes

List a file

$ ls -l --time-style=+%F script.sh
-rwxr-xr-x 1 rsc users 0 2026-11-23 script.sh

The first ten characters show the file type and the owner, group, and other permission bits.

See: File permissions

Read the numeric mode

$ stat -c '%A %a' script.sh
-rwxr-xr-x 755

stat prints both forms, which is handy after a recursive change.

See: stat invocation

Special bits

Setuid

$ chmod u+s program
$ stat -c '%A %a' program
-rwsr-xr-x 4755

The owner's x becomes s and the numeric mode gains a leading 4.

See: File permissions

Setgid

$ chmod g+s shared/
$ stat -c '%A %a' shared/
drwxr-sr-x 2755

On a directory, new entries inherit its group; the leading digit becomes 2.

See: Directory setuid and setgid

Sticky bit

$ chmod 00777 shared/
$ chmod +t shared/
$ stat -c '%A %a' shared/
drwxrwxrwt 1777

A leading 0 clears inherited special bits. On a shared directory, unprivileged users can remove only their own entries; the directory owner and root are exempt.

See: File permissions

Numeric special bits

$ chmod 2755 shared/

Leading digit

DigitBit
4setuid
2setgid
1sticky

Combine it with the three access digits, eg chmod 2755 shared/.

See: Numeric modes

0 Comments for this cheatsheet. Write yours!