Find Cheatsheet
Basic Search
Find files and directories by name.
| Command | Description |
|---|---|
find . -name "file.txt"
|
Find an exact filename |
find . -iname "readme.md" |
Case-insensitive name search |
find /etc -name "*.conf" |
Find by extension |
find . -type d -name "backup" |
Find directories by name |
Filter by Type
Limit results to file system object type.
| Command | Description |
|---|---|
find . -type f |
Regular files only |
find . -type d |
Directories only |
find . -type l |
Symlinks only |
find . -type f -name "*.log" |
Files with a specific extension |
find . -maxdepth 1 -type f |
Search current directory only |
find . -type f -empty |
Find empty files |
find . -type d -empty |
Find empty directories |
Size Filters
Find files by size.
| Command | Description |
|---|---|
find . -type f -size +100M |
Larger than 100 MB |
find . -type f -size -10M |
Smaller than 10 MB |
find . -type f -size 1G |
Exactly 1 GB |
find /var -type f -size +500M
|
Large files under /var |
Time Filters
Filter by file modification, access, and change times.
| Command | Description |
|---|---|
find . -type f -mtime -7 |
Modified in last 7 days |
find . -type f -mtime +30 |
Modified more than 30 days ago |
find . -type f -atime -1 |
Accessed in last 24 hours |
find . -type f -ctime -3 |
Metadata changed in last 3 days |
find . -type f -mmin -60 |
Modified in last 60 minutes |
Permissions and Ownership
Find files based on permissions and owners.
| Command | Description |
|---|---|
find . -type f -perm 644 |
Exact permission match |
find . -type f -perm -u+w |
User-writable files |
find / -type f -user root |
Files owned by user |
find /srv -type f -group www-data |
Files owned by group |
Excluding Paths
Skip directories from search results.
| Command | Description |
|---|---|
find . -path ./node_modules -prune -o -type f -print |
Exclude one directory |
find . ( -path ./node_modules -o -path ./.git ) -prune -o -type f -print |
Exclude multiple directories |
find . -type f ! -name "*.log" |
Exclude one filename pattern |
find . -type f ! -path "*/cache/*" |
Exclude by path pattern |
Actions (-exec, -delete)
Run commands on matched files.
| Command | Description |
|---|---|
find . -type f -name "*.tmp" -delete |
Delete matches |
find . -type f -name "*.log" -exec gzip {} ; |
Run command per file |
find . -type f -name "*.jpg" -exec mv {} /tmp/images/ ; |
Move matched files |
find . -type f -name "*.conf" -exec grep -H "listen" {} ; |
Search text in matched files |
find . -type f -name "*.log" -exec rm {} + |
Batch delete (faster than ;) |
Safer Bulk Operations
Use null-delimited output for safe piping.
| Command | Description |
|---|---|
find . -type f -name "*.txt" -print0 | xargs -0 rm -f |
Safely remove files with spaces |
find . -type f -print0 | xargs -0 ls -lh |
Safe batch listing |
find . -type f -name "*.log" -print0 | xargs -0 du -h |
Safe size report for matches |
find . -type f -name "*.bak" -print0 | xargs -0 -I{} mv "{}" /tmp/backup/ |
Safe batch move |
Common Options
Useful flags to remember.
| Option | Description |
|---|---|
-name |
Match filename (case-sensitive) |
-iname |
Match filename (case-insensitive) |
-type |
Filter by file type |
-size |
Filter by size |
-mtime |
Filter by modification time (days) |
-maxdepth |
Limit recursion depth |
-mindepth |
Skip top levels |
-prune |
Exclude directories |
-exec |
Execute command on matches |
-empty |
Find empty files/directories |
-mmin |
Filter by modification time (minutes) |
-delete |
Delete matched files |
