Site icon New Generation Enterprise Linux

Stop blindly recursive chmodding your way into a mess

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

Stop blindly recursive chmodding your way into a mess

đź§© The Challenge

You have a directory full of files and folders, and you just want to fix the permissions for the files without nuking the execution bits on every single subdirectory. I’ve seen juniors run a flat chmod -R 755 and then wonder why the entire tree is suddenly locked down or publicly accessible.

đź’ˇ The Fix

Use the find command with the type flag to target only files or directories specifically. It saves you from that sinking feeling when you realize you’ve just broken your entire web root.

find /path/to/dir -type f -exec chmod 644 {} +
find /path/to/dir -type d -exec chmod 755 {} +

⚙️ Why It Works

Adding the -type f or -type d filter forces the operation to ignore the stuff you aren’t currently trying to fix. Because you’re using -exec with the plus sign, you’re actually bundling those files into batches for efficiency, which is way faster than launching a new process for every single file.

🚀 Pro-Tip: Always dry-run your find command with -print before you pipe the results into a chmod.

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

0 0 votes
Article Rating
Exit mobile version