A few years ago, I wasted 30 minutes looking for a misplaced log file—scrolling through directories, opening files manually, and running random ls
commands.
Then, I learned how to use find
properly—and found the file in 5 seconds.
If you are still clicking through directories or using slow GUI searches, it’s time to master the find
command. This guide will eliminate manual searching forever with real-world examples, not just a list of flags.
Need a quick-reference guide for Bash scripting?
👉 Get the Bash Cheat Book for $3.99
1. Stop Searching by Hand: Find Any File Instantly
Most Common Manual Search Mistake:
Manually navigating directories or using ls
to search for a file:
ls -lR /home/user | grep "report.pdf" # ❌ Slow and inefficient
✅ The Fix: Use find
for Instant Search
find /home/user -name "report.pdf"
🔹 Why it's better: Works even if you don’t remember the exact location.
🔹 Bonus: Make it case-insensitive:
find /home/user -iname "report.pdf"
2. Searching by File Type: Don't Get Unnecessary Results
Instead of listing everything, filter results by type.
Find Only Directories
find /home/user -type d -name "projects"
Find Only Files
find /var/log -type f -name "*.log"
🔹 Why it's useful: Stops wasting time sifting through irrelevant results.
3. Finding Large Files Eating Up Space
Instead of guessing which files are wasting disk space, use find
to locate big offenders instantly.
Find Files Larger Than 500MB
find /home -type f -size +500M
Find Files Between 50MB and 100MB
find /home -type f -size +50M -size -100M
🔹 Why it’s useful: Helps free up storage without digging through directories manually.
4. Find Recently Modified Files for Debugging
Finding recently edited files helps track down issues fast.
Find Files Modified in the Last 7 Days
find /var/log -type f -mtime -7
Find Files Modified More Than 30 Days Ago
find /var/log -type f -mtime +30
Find Files Modified in the Last 10 Minutes
find /var/log -type f -mmin -10
🔹 Why it's useful: Essential for debugging recent system changes.
5. Cleaning Up: Find and Delete Files in One Command
Stop manually deleting files one by one.
Delete All .tmp
Files in /tmp
find /tmp -type f -name "*.tmp" -delete
🚨 Test first before deleting:
find /tmp -type f -name "*.tmp" -print
🔹 Why it’s useful: Automates temporary file cleanup.
6. Batch Processing: Running Commands on Found Files
You can use find
to automate tasks across multiple files.
Change Ownership of All .log
Files
find /var/log -type f -name "*.log" -exec chown user:user {} \;
Move All .jpg
Files to Another Directory
find /home/user/Pictures -type f -name "*.jpg" -exec mv {} /backup/images/ \;
🚀 Pro Tip: If your command needs multiple files, use +
instead of \;
for better performance:
find /home/user/Pictures -type f -name "*.jpg" -exec mv {} /backup/images/ +
🔹 Why it's useful: Great for bulk renaming, moving, or modifying files.
7. Searching With Logical Operators: Combine Multiple Criteria
Find .log
OR .txt
Files
find /var/log -type f \( -name "*.log" -o -name "*.txt" \)
Find Files Modified in the Last 7 Days AND Larger Than 1MB
find /home -type f -mtime -7 -a -size +1M
🔹 Why it's useful: Refines searches to only return exactly what you need.
8. Finding Hidden Files (.*
Dotfiles)
List All Hidden Files in a Directory
find /home/user -type f -name ".*"
🔹 Why it’s useful: Quickly find dotfiles like .bashrc
, .gitconfig
, etc.
9. Searching for Files by Permission Settings
Find Files That Are World-Readable (644
)
find /home -type f -perm 644
Find Files That Are Executable (755
)
find /usr/bin -type f -perm 755
🔹 Why it's useful: Helps detect misconfigured permissions that could be security risks.
10. Finding Files Without a Certain Extension
Find All Files Except .log
find /var/log -type f -not -name "*.log"
🔹 Why it's useful: When you need to exclude certain file types from your search.
Final Thoughts: Stop Searching Manually
Mastering just a few find
tricks will eliminate wasted time spent manually looking for files.
Quick Recap:
✅ Find files by name, type, and size
✅ Search by modification time to track changes
✅ Use -exec
and -delete
for batch processing
Want a Structured Bash Reference?
If you need a Easy to Read Bash guide with real-world scripts, check out my Bash Cheat Sheet:
👉 Download the Bash Cheat Book for just $3.99
What’s Inside?
✔️ Essential Bash commands for automation
✔️ File handling, process management, and troubleshooting tips
✔️ Formatted PDF for offline use
Discussion: What’s the Most Useful find
Trick You Use?
Drop a comment below and share your best find
command use case!
Top comments (0)