The Swiss Army knife of file search
find walks a directory tree applying tests and actions to every entry. Once you internalize the syntax, you can answer almost any "where is the file that..." question.
The shape
find <path> <tests> <action>. Path defaults to . if omitted (BSD requires it explicitly; macOS works either way in practice). Tests filter; the default action is -print.
The tests you'll use most
-name 'pattern'— glob match the basename. Quote it!-iname 'pattern'— case-insensitive.-type f— regular files. Also:ddir,lsymlink.-size +10M— bigger than 10 MB.-1k,+500c(chars).-mtime -7— modified in the last 7 days.-mmin -60for minutes.-empty— empty files or dirs.-maxdepth 2— don't recurse deeper. Put it before other tests for performance.
Actions
-print— default. Print path.-delete— delete the match. Test with-printfirst!-exec cmd {} \;— run cmd once per match.-exec cmd {} +— batch matches into one cmd invocation. Like xargs but built in.
Real one-liners
- Find every Python file under home:
find ~ -name '*.py' - Files bigger than 100 MB:
find / -type f -size +100M 2>/dev/null - Old logs to delete:
find /var/log -name '*.log' -mtime +30 -delete - Pass to grep:
find . -name '*.go' -exec grep -l TODO {} +
For interactive search, the fd tool from the modern-tools track is faster and friendlier — but find is on every Unix box.