find Cheatsheet
Top patterns.
Overview
find is the Unix file-tree traversal tool, present on every Unix box. Five primitives carry most operational use: name matching by glob, type filtering, time-based filtering, size filtering, action via -exec or -delete. Fluency turns "where is X" into a specific query within seconds.
- Name matching.
-nameand-inamematch by glob. Precise file selection. - Type filtering.
-type ffor files,-type dfor directories,-type lfor symlinks. Avoids surprises. - Time and size filtering.
-mtime,-atime,-ctimefor time;-sizefor size. Supports cleanup and disk-debugging investigations. - Action via
-execor-delete. Run commands on matches or delete them in place. Composable with shell pipelines.
The approach
Start broad, narrow down with filters, prefer -print0 | xargs -0 for safe handling of weird filenames, use -exec for one-shot commands and xargs for parallel operations. Five idioms cover most operational use; memorising them moves the team from manual scrolling to confident shell-driven cleanup.
find . -name "*.log". Find all log files under the current directory. First move on most file investigations.find . -mtime +30 -type f. Files modified more than 30 days ago. Standard cleanup query.find . -size +100M. Files larger than 100MB. Standard disk-debugging query.find . -name "*.tmp" -print0 | xargs -0 rm. Safe handling of weird filenames;-print0plusxargs -0avoids whitespace bugs.
Why this compounds
Each one-liner that lands in muscle memory shortens the next investigation. Find in scripts produces scheduled cleanup; find on the command line produces fast disk-management investigations. By year two, find is the first tool reached for any file-system question.
- Faster cleanup. One-liners replace manual scrolling. Disk management gets fast.
- Better automation. Find in scripts produces scheduled cleanup. Operations scale.
- Universal availability. Present on every Unix box. No dependencies.
- Year-one investment, year-two habit. First year builds fluency; by year two, find is the reflexive first tool for file-system questions.