Knowledge

How to change file permissions with chmod

#CommandLine

Change Linux and macOS file permissions with chmod using symbolic and numeric modes, recursive changes, and why 777 is rarely the answer.

Published by Mark van Eijk on June 23, 2026 · 2 minute read

  1. How Linux permissions work
  2. Symbolic mode
  3. Numeric (octal) mode
  4. Recursive changes
  5. A word on 777

How Linux permissions work

Every file and directory on Linux and macOS has permissions for three groups: the user (owner), the group, and others (everyone else). Each group can have three permissions: read (r), write (w), and execute (x).

Run ls -l and you'll see them on the left:

ls -l
-rw-r--r--  1 jane staff  1240 Jun 23 10:00 notes.txt

The first character is the file type (- for a file, d for a directory). The next nine are three blocks of rwx: owner, group, others. Above, the owner can read and write, while group and others can only read.

chmod ("change mode") is how you adjust those bits.

Symbolic mode

Symbolic mode is the readable way to make targeted changes. You name the target (u user, g group, o others, a all), then +, -, or =, then the permission.

chmod u+x deploy.sh    # give the owner execute
chmod g-w report.txt   # remove write from the group
chmod o=r config.ini   # set others to read-only exactly
chmod a+r public.txt   # give everyone read

The + adds, - removes, and = sets exactly (clearing anything not listed). This is my go-to when I just need to flip one bit. Making a script runnable is so common I gave it its own write-up: make a script executable with chmod +x.

Numeric (octal) mode

Numeric mode sets all three groups at once. Each digit is the sum of read (4), write (2), and execute (1):

  • 7 = rwx (4+2+1)
  • 6 = rw- (4+2)
  • 5 = r-x (4+1)
  • 4 = r--

The three digits are owner, group, others, in that order:

chmod 755 deploy.sh    # rwxr-xr-x — owner full, others read+execute
chmod 644 notes.txt    # rw-r--r-- — owner read+write, others read
chmod 600 secret.key   # rw------- — owner only

755 is the standard for scripts and directories; 644 is standard for regular files.

Recursive changes

To apply a mode to a directory and everything inside it, add -R:

chmod -R 755 ./public

Be careful here. Files and directories usually want different permissions (directories need execute to be enterable), so a blanket recursive chmod can break things. When that matters I use find to target each type separately:

find ./public -type d -exec chmod 755 {} \;
find ./public -type f -exec chmod 644 {} \;

A word on 777

You'll see chmod 777 suggested as a quick fix all over the internet. It grants read, write, and execute to everyone, which is almost never what you want. On a shared server it's a real security risk. If something isn't working, the fix is usually correct ownership (chown) or a sensible 644/755, not throwing the doors wide open.

Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

Related articles

Argument list too long (Bash: /bin/rm)

Change Linux and macOS file permissions with chmod using symbolic and numeric modes, recursive changes, and why 777 is rarely the answer.

Read more →

How to install Composer packages locally

Change Linux and macOS file permissions with chmod using symbolic and numeric modes, recursive changes, and why 777 is rarely the answer.

Read more →