chmod X (capital X)
Answer
A capital X in a chmod operation adds execute permission only to directories and to files that already have execute set for someone. Ordinary data files are left non-executable, which makes X the safe choice with chmod -R.
chmod a+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 | 644 rw-r--r-- |
600 | file | 600 rw------- |
755 | directory | 755 rwxr-xr-x |
700 | directory | 711 rwx--x--x |
What to know
chmod -R a+X dir makes every directory in the tree enterable without marking every data file executable: a 644 file stays 644, a 644 directory becomes 755, and a 700 script becomes 711.
The common recipe for a web or project tree is chmod -R u=rwX,go=rX dir. Directories end up 755, plain files 644, and files that were already executable 755.
Where it fits
- Resetting a whole tree after an accidental
chmod -R 777or a bad archive extraction - Making a copied directory tree readable by other users (
chmod -R go+rX dir) - Private trees:
chmod -R u=rwX,go= dirgives directories 700 and files 600
Gotchas
- X looks at whether a file has any execute bit at the moment it is applied. A data file that was wrongly made executable (for example by a previous 777) keeps execute; fix those separately with
find dir -type f -exec chmod a-x {} +if needed. - X has no octal form. Numeric modes like
chmod -R 755cannot tell files and directories apart. chmod +Xwith no who-letter is filtered by the umask, the same way as chmod +x. Writea+Xto be explicit.
Related explainers
- chmod +xchmod +x adds execute permission so a script can be run as ./script. Who gets it, why the umask filters it...
- 755 vs 644755 and 644 differ only in the execute bit. Use 755 for directories and programs, 644 for regular files;...
- 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 777 (rwxrwxrwx)chmod 777 lets every user on the system read, change and run a file. Why it is almost always the wrong fix...