Find Command Cheat Sheet
Search files and directories by name, type, size, date, ownership, permissions and content. Built for real server troubleshooting, cleanup work and day-to-day Linux support.
Syntax
Basic structure
find [path] [tests] [actions]Start with the location, add tests to match files, then optionally add an action.
Search current directory
find . -name "*.log"Search a website folder
find /home/user/public_html -type f -name "*.php"Case-insensitive name search
find . -iname "*backup*"Find by name and type
| Task | Command |
|---|---|
| Find files named error_log | find . -type f -name "error_log" |
| Find all PHP files | find public_html -type f -name "*.php" |
| Find directories only | find . -type d |
| Find symlinks | find . -type l |
| Find hidden files | find . -name ".*" |
| Find multiple extensions | find . -type f \( -name "*.zip" -o -name "*.tar.gz" -o -name "*.sql" \) |
Find by size and date
Large files
find /home/user -type f -size +500M -exec ls -lh {} \;Empty files
find . -type f -emptyModified in last 24 hours
find public_html -type f -mtime -1Older than 30 days
find /home/user/logs -type f -mtime +30| Test | Meaning |
|---|---|
-mtime -7 | Modified less than 7 days ago. |
-mtime +30 | Modified more than 30 days ago. |
-size +100M | Larger than 100 MB. |
-size -10k | Smaller than 10 KB. |
Ownership and permissions
Files owned by a user
find /home -user usernameFiles not owned by account user
find /home/user/public_html ! -user user -lsWorld writable files
find public_html -type f -perm -002 -ls777 directories
find public_html -type d -perm 0777 -lsActions and exec
Safety: run the command with
-print or -ls first. Only add -delete or -exec rm after checking the matches.| Action | Example |
|---|---|
| Print full path | find . -type f -name "*.log" -print |
| Show details | find . -type f -size +100M -ls |
| Run ls on matches | find . -type f -name "*.php" -exec ls -lh {} \; |
| Delete old logs | find /home/user/logs -type f -name "*.log" -mtime +30 -delete |
| Use xargs safely | find . -type f -name "*.log" -print0 | xargs -0 du -h |
Server support recipes
Find recently changed PHP files
find /home/user/public_html -type f -name "*.php" -mtime -2 -lsFind backups left in public_html
find /home/user/public_html -type f \( -name "*.zip" -o -name "*.tar.gz" -o -name "*.sql" -o -name "*.bak" \) -lsFind big email files
find /home/user/mail -type f -size +50M -exec ls -lh {} \;Find old cache files
find /home/user/public_html -type f -path "*/cache/*" -mtime +14 -lsSafety tips
- Quote wildcards, for example
"*.php", so the shell does not expand them beforefindruns. - Use
-lsbefore destructive actions. - Prefer
-deleteonly after the path and tests are very specific. - Use
\( ... \)around grouped OR conditions. - Remember that
-mtime +30means older than 30 days, while-mtime -30means newer than 30 days.
Find command workflows you will actually use
Find large log files
find /home -type f -name "*.log" -size +100M -exec ls -lh {} \;Find recently changed PHP files
find /home/user/public_html -type f -name "*.php" -mtime -2 -printFind writable files
find /home/user/public_html -type f -perm /022 -lsFind empty files
find . -type f -empty -printPreview first. Add actions like
-delete only after the non-destructive command shows exactly what you expect.Example find output
$ find . -type f -name "*.log" -size +100M -exec ls -lh {} \;
-rw-r--r-- 1 user user 248M May 5 10:01 ./logs/access.log
-rw-r--r-- 1 user user 131M May 5 10:02 ./logs/debug.log
Frequently Asked Questions
How do I find files by name?
Use find PATH -name "pattern", for example find . -name "*.log".
How do I find files larger than 100 MB?
Use find . -type f -size +100M.
How do I safely delete files with find?
Run the same command without -delete first, verify the output, then add -delete only when the match is correct.
How do I find recently modified files?
Use -mtime for days or -mmin for minutes, for example find . -type f -mtime -1.