- 1View File Permissions in Linux
- 2Change File Permissions with chmod in Linux
- 3How to Use Numeric Mode with chmod in Linux
- 4chmod Symbolic Mode in Linux
- 5How to Change File Ownership in Linux
- 6How to Change Group Ownership Using chgrp in Linux
- 7Understanding Linux File Permission Symbols (r, w, x)
- 8Linux File Permissions - User, Group, Others
- 9Understanding Special Permissions in Linux: SUID, SGID, and Sticky Bit
- 10How to Use ACLs in Linux - Set File Permissions
- 11Set ACL Permissions in Linux with setfacl
- 12How to View ACLs using getfacl in Linux
- 13Find Files by Permissions in Linux
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
Loading comments...