Skip to main content

Find Cheatsheet

Syntax Reminder

find [PATH] [GLOBAL OPTS] [TESTS] [ACTIONS]

Always: tests before actions.

Search by Name

GoalCommand
Exact namefind / -name "nginx.conf"
Glob patternfind / -name "*.log" (quote it!)
Case insensitivefind / -iname "readme.txt"
Full path matchfind . -path "*/archive/*.log"

Search by Type

GoalCommand
Files onlyfind . -type f
Directories onlyfind . -type d
Symlinks onlyfind . -type l
Broken symlinksfind . -type l -xtype l
Empty filesfind . -type f -empty
Empty directoriesfind . -type d -empty

Search by Size

GoalCommand
Larger than 1 GBfind / -size +1G
Smaller than 10 KBfind . -size -10k
Between 10–50 MBfind . -size +10M -size -50M

Search by Time

GoalCommand
Modified in last 24hfind . -mtime -1
Modified > 30 days agofind . -mtime +30
Changed in last 60 minfind . -cmin -60
Newer than a referencefind . -newer /path/to/ref.txt

Search by Owner / Permissions

GoalCommand
Owned by user nginxfind /var -user nginx
Owned by group devsfind /var -group devs
Exact perms 0644find . -perm 0644
SUID bit setfind / -perm /4000
World writablefind / -perm /0002
Orphaned (no user)find / -nouser

Actions

GoalCommand
Delete matchesfind . -name "*.tmp" -delete
Run cmd per filefind . -name "*.bak" -exec rm {} \;
Run cmd batchedfind . -name "*.bak" -exec rm {} +
Safe directory execfind . -exec chmod 644 {} \;
Null-safe pipefind . -print0 | xargs -0 grep "term"

Pruning & Depth

GoalCommand
Max depth 1find . -maxdepth 1
Skip current dirfind . -mindepth 1
Prune node_modulesfind . -name node_modules -prune -o -name "*.js" -print

Quick Recipes

# Compress logs > 7 days old
find /var/log -name "*.log" -mtime +7 -exec gzip {} +

# Delete old backups, keep 30 days
find /backups -type f -mtime +30 -delete

# Find and fix world-writable scripts
find /usr/local/bin -type f -perm /0002 -exec chmod o-w {} +

# Find big files eating disk space
find / -type f -size +500M -exec ls -lh {} \; 2>/dev/null

# Find recently changed configs (security audit)
find /etc -type f -mmin -1440 # last 24h in minutes