📖 Guide
Find — Complete Reference
Comprehensive find cheat sheet covering name, type, size, time, permission filters, actions, combined expressions, and common patterns.
58 commands across 9 categories
Basic Usage
| Command | Description |
|---|---|
find . | List all files and directories recursively from current directory |
find /path/to/dir | Search starting from a specific directory |
find . -maxdepth 1 | Limit search to current directory only (no recursion) |
find . -mindepth 2 | Skip the first level; start searching from depth 2 |
find . -maxdepth 3 -mindepth 2 | Search only at depth 2 and 3 |
find . -follow | Follow symbolic links during search |
By Name
| Command | Description |
|---|---|
find . -name '*.txt' | Find files matching a glob pattern (case-sensitive) |
find . -iname '*.jpg' | Find files matching pattern (case-insensitive) |
find . -name '*.log' -not -name 'error.*' | Match one pattern but exclude another |
find . -path '*/src/*.ts' | Match against the full path, not just filename |
find . -regex '.*\.[ch]pp$' | Match filename using full regex |
find . -name '.*' | Find hidden files (dotfiles) |
By Type
| Command | Description |
|---|---|
find . -type f | Find regular files only |
find . -type d | Find directories only |
find . -type l | Find symbolic links only |
find . -type f -empty | Find empty files |
find . -type d -empty | Find empty directories |
find . -type f -executable | Find executable files (GNU find) |
By Size
| Command | Description |
|---|---|
find . -size +100M | Find files larger than 100 MB |
find . -size -1k | Find files smaller than 1 KB |
find . -size 0 | Find zero-byte files |
find . -size +1G | Find files larger than 1 GB |
find . -size +10M -size -100M | Find files between 10 MB and 100 MB |
find . -type f -size +50M -exec ls -lh {} + | List large files with human-readable sizes |
By Time
| Command | Description |
|---|---|
find . -mtime -7 | Files modified in the last 7 days |
find . -mtime +30 | Files modified more than 30 days ago |
find . -atime -1 | Files accessed in the last 24 hours |
find . -ctime -7 | Files with status changed in the last 7 days |
find . -mmin -60 | Files modified in the last 60 minutes |
find . -newer reference.txt | Files modified more recently than reference.txt |
find . -newermt '2024-01-01' | Files modified after a specific date (GNU find) |
By Permissions
| Command | Description |
|---|---|
find . -perm 644 | Find files with exact permissions 644 |
find . -perm -u+x | Find files where owner has execute permission |
find . -perm /o+w | Find files where others have write permission |
find . -user root | Find files owned by root |
find . -group staff | Find files owned by group 'staff' |
find . -nouser | Find files with no matching user in /etc/passwd |
find . -perm -4000 | Find setuid files (potential security concern) |
Actions
| Command | Description |
|---|---|
find . -name '*.tmp' -delete | Delete matching files (use with caution!) |
find . -type f -exec chmod 644 {} \; | Run command on each file (\; runs once per file) |
find . -type f -exec chmod 644 {} + | Run command with multiple files at once (more efficient) |
find . -name '*.log' -exec rm -i {} \; | Interactive delete (asks for each file) |
find . -name '*.js' -print0 | xargs -0 wc -l | Pipe to xargs with null delimiter (handles spaces in names) |
find . -type f -ok mv {} /backup/ \; | Like -exec but prompts for confirmation on each file |
find . -name '*.txt' -exec grep -l 'pattern' {} + | Find files containing a specific pattern |
Combining Expressions
| Command | Description |
|---|---|
find . -name '*.js' -o -name '*.ts' | OR: match .js or .ts files |
find . -name '*.log' -a -size +1M | AND: match .log files larger than 1 MB (default operator) |
find . ! -name '*.txt' | NOT: exclude .txt files |
find . \( -name '*.js' -o -name '*.ts' \) -newer ref.txt | Group expressions with parentheses |
find . -name '*.bak' -prune -o -name '*.txt' -print | Exclude a pattern from results using -prune |
find . -path './node_modules' -prune -o -name '*.js' -print | Skip node_modules directory entirely |
Common Patterns
| Command | Description |
|---|---|
find . -name 'node_modules' -type d -prune -exec rm -rf {} + | Recursively delete all node_modules directories |
find . -type f -name '*.py' | wc -l | Count Python files in a project |
find . -type f -mtime +90 -delete | Clean up files older than 90 days |
find . -type f -printf '%s %p\n' | sort -rn | head -20 | Find 20 largest files with sizes (GNU find) |
find . -type l ! -exec test -e {} \; -print | Find broken symbolic links |
find . -type f -name '*.jpg' -exec cp {} /backup/photos/ \; | Copy all JPG files to a backup directory |
find /var/log -name '*.gz' -mtime +30 -delete | Clean up old compressed log files |
📖 Free, searchable command reference. Bookmark this page for quick access.