Home·Terminal commands

chmod

Permissions

Usage

chmod 755 [path]

Sets the permission bits on files and directories; chmod -R 755 makes plain files executable too, so use the capital X form to leave files alone.

Common flags

FlagMeaning
0755Numeric: owner, group, others, each read 4 + write 2 + execute 1
u+wSymbolic: who (u g o a), then + - =, then r w x
+xAdd the execute bit, the usual fix for a script
-RApply to a whole tree
+XExecute for directories only, never for plain files
-vName each file whose mode changed
-hBSD and macOS: change the symlink itself, not its target

Examples

chmod +x deploy.sh

Makes the script runnable.

chmod -R u+rwX,go+rX,go-w site/

Capital X keeps files non-executable.

chmod 600 ~/.ssh/id_ed25519

What ssh insists on for a private key.

Numeric and symbolic modes name the same thing: 755 and u=rwx,go=rx are the same permission.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does chmod do?

Sets the permission bits on files and directories; chmod -R 755 makes plain files executable too, so use the capital X form to leave files alone.

Q. How do I type it?

chmod 755 [path] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man chmod. This command sits under Permissions.

Related commands

man page: man chmod