chmod +x
chmod +x file adds the execute bit so the file can be run directly, as ./file. With no u, g, o or a in front, GNU chmod adds execute for everyone except where your umask blocks it, so a 644 file usually becomes 755.
chmod +x on common starting modes
Computed with the umask at 022, the usual default. Checked against GNU chmod on real files.
| Before | Type | After |
|---|---|---|
644 | file | 755 rwxr-xr-x |
600 | file | 711 rwx--x--x |
755 | directory | 755 rwxr-xr-x |
700 | directory | 711 rwx--x--x |
What to know
When the clause has no who-letter, chmod behaves like a+x but leaves alone any bit that is set in the umask. With the common umask 022, execute is not masked, so all three classes get it: 644 becomes 755. With umask 077, only the owner gets it: 644 becomes 744.
To be explicit, name the class: chmod u+x (only you), chmod ug+x, or chmod a+x (everyone, regardless of umask).
Execute alone is not enough for a script to run: it also needs a first line such as #!/bin/sh or #!/usr/bin/env python3, or the shell will not know which interpreter to use.
Where it fits
- Shell, Python or other scripts you want to run as
./script.sh - Downloaded binaries and installers (after verifying them)
- Git hooks in
.git/hooks/, which are ignored unless executable
Gotchas
- "Permission denied" right after
chmod +xoften means the file is on a filesystem mountednoexec(common for /tmp and some home or USB mounts). Run it assh script.shor move it. - Git records the executable bit. On systems where it is not preserved, use
git update-index --chmod=+x script.shso the bit is committed. - The umask filter also applies to
chmod -wandchmod =rwith no who-letter. GNU chmod prints a warning when the result differs from what you typed.
Related explainers
- chmod 755 (rwxr-xr-x)chmod 755 gives the owner read, write and execute, and everyone else read and execute. When to use it for...
- chmod X (capital X)Capital X in chmod adds execute only to directories and to files that already have an execute bit. Use it...
- umask 022umask 022 means new files are created 644 (rw-r--r--) and new directories 755 (rwxr-xr-x). How the umask...
- umask 077umask 077 creates files as 600 and directories as 700, so nothing you create is visible to other users....