How to Find Files with Specific Permissions in Linux

How to Find Files with Specific Permissions in Linux

Hey there! 👋 Welcome to today's Linux tutorial, where we'll learn how to find files that have specific permissions using the find command.

This is especially useful when you want to check if any files are world-writable or if any have too many open permissions. Let's dive in!

🔍 The Command We'll Use

The tool for this is the find command. It lets us search the filesystem for files that match given conditions—including permission bits.

🧪 Example Scenario

Let’s say you want to find all files in your current directory and its subdirectories that have the permission 777 — which means read, write, and execute access for everyone (owner, group, and others). That’s risky!

💡 Basic Syntax

find [path] -type f -perm [mode]

Here's how it works:

  • path: where to start searching (e.g., . for current directory)
  • -type f: only look for files
  • -perm: match specific permission mode

✅ Example: Find Files with 777 Permissions

find . -type f -perm 0777

📤 Output:

./public/test.sh
./scripts/dev_tool.sh

Whoa! These files are accessible by anyone. You might want to fix that. 😅

🔒 Example: Find Files Writable by Others

You can also search for files that are writable by others (world-writable), even if they don’t have full 777 permissions.

find . -type f -perm -0002

This matches any file that has the others write bit set.

🖨 Output might look like:

./logs/debug.log
./uploads/tmp_file.txt

🔍 Find Files with Exact Permissions Only

If you want to find files that match exactly the permission bits (no more, no less), use:

find . -type f -perm 0644

Only files with permissions -rw-r--r-- will be listed. Files with extra bits (like execute) will be skipped.

⚠️ Optional: Ignore Permission Errors

If you're running into “Permission denied” errors, add 2>/dev/null to suppress them:

find / -type f -perm 0777 2>/dev/null

🧠 Summary

  • Use find . -type f -perm 0777 to locate risky files.
  • Use perm -0002 to find world-writable files.
  • Add 2>/dev/null to hide permission errors.

That’s it! You now know how to search for files based on permissions. Practice these on a safe folder before running them on critical directories. 🛡️

See you in the next lesson, and happy learning! 🚀

Comments

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...