chmod -R: changing permissions recursively and safely
How to use chmod -R to change permissions on a whole directory tree without making files executable—plus the find and capital-X tricks that keep folders usable.
Quick Answer
chmod -R applies a mode to every file and folder in a tree, which is dangerous because the same mode rarely suits both. Apply 755 to directories and 644 to files separately with find, or use the capital-X mode so execute is added only to directories and already-executable files.
Search Snapshot
- Format
- Engineering
- Reading time
- 4 min
- Last updated
- June 12, 2026
- Primary topic
- chmod recursive
- Intent
- informational
Key Takeaways
Point 1
A blanket chmod -R 755 marks every document executable; a blanket 644 locks every directory.
Point 2
Use find with -type d and -type f to set folders and files to different modes.
Point 3
The capital-X mode adds execute only to directories and files that already had it.
The -R flag turns chmod into a recursive operation that walks an entire directory tree. It is enormously useful for fixing a folder of files in one command, but it is also the single most common way people break a project's permissions. The chmod recursive trap is simple: the same mode is rarely right for both files and directories, so applying one blindly damages half of them.
Why a blanket recursive mode hurts
Picture a project folder with scripts, source files, images and nested directories. Run chmod -R 755 and every file becomes executable—your README, your CSS, your JSON config—which is misleading and occasionally exploitable. Run chmod -R 644 instead and every directory loses its execute bit, so nobody can enter the folders or reach the files within. Neither single mode is correct because directories genuinely need execute while ordinary files do not. The recursive flag amplifies whichever mistake you make across the whole tree at once.
| Command | Effect on directories | Effect on files |
|---|---|---|
| chmod -R 755 path | Correct (traversable) | Wrong (all marked executable) |
| chmod -R 644 path | Wrong (cannot be entered) | Correct (read-write owner) |
| find -type d → 755 + find -type f → 644 | Correct | Correct |
| chmod -R a+rX path | Execute added | Execute added only where already set |
What a single recursive mode does to a mixed tree.
The safe pattern with find
The reliable approach treats directories and files as separate jobs. First set the folders, then set the files:
find /path -type d -exec chmod 755 {} +
find /path -type f -exec chmod 644 {} +
The first command finds every directory and makes it traversable. The second finds every regular file and makes it owner-writable and world-readable without the execute bit. The result is a clean tree where folders work and files are not pretending to be programs. Confirm the two modes in the chmod calculator before you run anything against a large tree.
The capital-X shortcut
There is a one-command alternative for the common case. The capital X mode adds the execute bit only to directories and to files that already had execute set for at least one class. So chmod -R a+rX /path grants read to everyone everywhere and execute only where it belongs. It is a precise tool: ordinary files stay non-executable while directories and existing programs keep working. Lowercase x would execute-flag everything, so the capital letter is the whole point.
A note on ownership
Permissions are only half the picture. If a recursive change does not fix access, the real problem is often ownership rather than mode, which chown controls. A file owned by the wrong user will refuse access no matter how generous the bits are. The chmod 755 vs 644 guide covers picking the right base modes and octal vs symbolic notation explains the a+rX syntax used above.
Frequently asked questions
Why is chmod -R 755 on everything a bad idea?
It gives every regular file the execute bit, so documents and configs become executable. Directories need 755 but files usually want 644, so one recursive mode cannot suit both.
How do I set directories to 755 and files to 644 at once?
Run find twice: once with -type d to set folders to 755 and once with -type f to set files to 644.
Bottom line
Reach for chmod -R with care. Never apply one numeric mode to a mixed tree—split the job by type with find, or use the capital-X mode so execute lands only on directories and existing programs. Model the target modes in the chmod calculator first and the recursive change becomes routine rather than risky.
Get new playbooks weekly
Actionable guides, market updates and shipping notes — once a week.