Site icon New Generation Enterprise Linux

Stop wrestling with recursive chmod when you only need directories

Permissions & Security (Chmod/Chown/ACLs/SELinux/AppArmor)

Stop wrestling with recursive chmod when you only need directories

đź§© The Challenge

You have a massive directory tree where files and folders have totally different needs, and you accidentally nuked your execution bits by running a standard chmod -R. I’ve wasted entire afternoons fixing that mess because my scripts suddenly couldn’t traverse anything.

đź’ˇ The Fix

Use the capital X flag instead of the lowercase x, which acts like a smart filter. It only applies the executable bit to directories or files that already have some sort of execute permission set.

chmod -R u+rwX,go-rwx,go+rX /path/to/web/root

⚙️ Why It Works

By using the capital X, you’re telling the kernel to ignore regular files unless they are already marked executable, preventing you from accidentally making your configuration files or logs runnable. It’s a lifesaver when you’re cleaning up inherited permissions on a messy web server.

🚀 Pro-Tip: Always run it with a dry run first if you’re feeling nervous, but honestly, this flag is the single best way to avoid shooting yourself in the foot.

Linux Tips & Tricks | © ngelinux.com | 9/22/2026

0 0 votes
Article Rating
Exit mobile version