Stop chmodding recursively and breaking your directory permissions

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

Stop chmodding recursively and breaking your directory permissions

🧩 The Challenge

Everyone has accidentally run chmod -R 755 on a root directory because they needed to fix one file and didn’t feel like typing out a specific path. Then your directories lose their execute bits, and suddenly you can’t cd into anything anymore.

💡 The Fix

Use the capital X flag with chmod, which only applies the execute permission to directories while leaving your regular files alone. It saves you from that pit of despair where you have to manually hunt down every directory you just broke.

chmod -R u+rwX,go+rX /path/to/your/directory

⚙️ Why It Works

Adding that capital X tells the system to only grant execute permissions if the file is already a directory or if it happens to have execute permission for someone else. It’s the difference between a functional file system and an afternoon spent restoring from backups.

🚀 Pro-Tip: Always dry run with –changes if you’re feeling nervous, so you can see exactly which files are getting touched before you commit to it.

Linux Tips & Tricks | © ngelinux.com | 7/16/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted