chmod -R applies a mode to a directory and everything inside it:
chmod -R u+rwX,go-w ~/proj
The trap: chmod -R 755 breaks nothing, chmod -R 644 breaks everything
The naive recursive command is chmod -R 755 dir or chmod -R 644 dir. The second is a disaster: it strips the execute bit from directories, and a directory without execute cannot be entered. Suddenly you cannot cd into your own folders or reach the files inside, even though you can see the names.
The reason is that numeric modes apply the same nine bits to files and directories alike, but directories need the execute bit and regular files usually should not have it.
The fix: capital X
chmod has a special mode X (capital) that means "execute, but only for directories and files that are already executable". It is exactly what recursive operations want:
# Owner full access; group/other read; directories stay traversable; plain files don't become executable
chmod -R u=rwX,go=rX ~/projX adds the execute bit to directories (so they stay enterable) and to files that already had execute (so scripts keep working), but it does not make every text file executable. This is the single most useful chmod fact most people never learn.
Better still: target files and directories separately
When you want precise control, use find to split the two:
find ~/proj -type d -exec chmod 755 {} + # directories: 755
find ~/proj -type f -exec chmod 644 {} + # files: 644-type d matches directories, -type f matches regular files, so each gets the mode that actually fits it. This is the bulletproof version for a web root or a release artifact. For more on the find side, see find files by owner, group, or permission.
FAQ
644 has no execute bit, and a directory needs execute to be entered. Applied recursively, it stripped execute from every directory, so you can no longer cd into them or reach files by path. Fix it with chmod -R u=rwX,go=rX dir, where the capital X restores execute on directories without making plain files executable.
Lowercase x sets the execute bit on everything it touches, including plain files. Capital X sets execute only on directories and on files that are already executable. For recursive operations you almost always want capital X so you do not turn every text file into a program.
Use find to separate them: find dir -type d -exec chmod 755 {} + for directories and find dir -type f -exec chmod 644 {} + for files. This is the most reliable way to fix a tree where files and directories need different modes.
See also
- Linux file permissions explained: the rwx and octal model behind this.
- How to make a file executable (chmod +x): the single-file case.
- Find files by owner, group, or permission: the find -type split in depth.
- How to change file owner and group (chown): chown -R, the ownership equivalent.
- Chmod calculator: work out the octal for a mode without doing the arithmetic by hand.
Sources
Authoritative references this article was fact-checked against.





