find - Locate Files by Name, Type, or Age
Learn find to locate files anywhere on your system. Search by name, size, date, or type without memorizing your folder structure.
find: Stop Guessing Where You Put That File
You know you have a file called config.json somewhere. You don't remember where. You could click through folders for ten minutes, or:
find . -name "config.json"
There it is. ./src/settings/config.json. That's find.
The Basic Pattern
find [where to look] [what to match]
The . means "current directory and everything under it." Use / for the entire system, ~ for your home folder, or any path you want.
Finding by Name
Exact match:
find . -name "README.md"
Wildcard:
find . -name ".txt"
All text files, anywhere in the tree.
Case-insensitive:
find . -iname "readme.md"
Matches README.md, Readme.md, readme.MD, etc.
Finding by Type
Only files (not directories):
find . -type f -name ".log"
Only directories:
find . -type d -name "test"
Finding by Time
Modified in the last 7 days:
find . -mtime -7
Modified more than 30 days ago:
find . -mtime +30
Minus means "less than", plus means "more than."
Finding by Size
Larger than 100MB:
find . -size +100M
Smaller than 1KB:
find . -size -1k
Suffixes: c (bytes), k (kilobytes), M (megabytes), G (gigabytes).
Limiting Depth
Don't want to search forever?
find . -maxdepth 2 -name ".js"
Only goes 2 levels deep.
Real Examples
Find all node_modules folders:
find . -type d -name "node_modules"
Find large files hogging space:
find . -type f -size +50M
Find old log files:
find /var/log -name ".log" -mtime +90
find vs grep
Different tools, different jobs:
- find searches for files by name, size, date
- grep searches for text inside files
Chain them together:
find . -name ".log" | xargs grep "error"
Find all log files, then search inside them.
Quick Reference
| What you want | Command |
|---------------|---------|
| By name | find . -name "file.txt" |
| Wildcard | find . -name ".js" |
| Case-insensitive | find . -iname "readme" |
| Only files | find . -type f |
| Only directories | find . -type d |
| Recent files | find . -mtime -7 |
| Large files | find . -size +100M |
| Limit depth | find . -maxdepth 2 |
Practice
find is essential in CTF challenges where flags hide in unexpected places. Master find and nothing stays hidden for long.
Yes, find has a hundred flags. You need five. The ones above cover 95% of real searching.*