Linux file search

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

TaskCommand
Find files named error_logfind . -type f -name "error_log"
Find all PHP filesfind public_html -type f -name "*.php"
Find directories onlyfind . -type d
Find symlinksfind . -type l
Find hidden filesfind . -name ".*"
Find multiple extensionsfind . -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 -empty

Modified in last 24 hours

find public_html -type f -mtime -1

Older than 30 days

find /home/user/logs -type f -mtime +30
TestMeaning
-mtime -7Modified less than 7 days ago.
-mtime +30Modified more than 30 days ago.
-size +100MLarger than 100 MB.
-size -10kSmaller than 10 KB.

Ownership and permissions

Files owned by a user

find /home -user username

Files not owned by account user

find /home/user/public_html ! -user user -ls

World writable files

find public_html -type f -perm -002 -ls

777 directories

find public_html -type d -perm 0777 -ls

Actions and exec

Safety: run the command with -print or -ls first. Only add -delete or -exec rm after checking the matches.
ActionExample
Print full pathfind . -type f -name "*.log" -print
Show detailsfind . -type f -size +100M -ls
Run ls on matchesfind . -type f -name "*.php" -exec ls -lh {} \;
Delete old logsfind /home/user/logs -type f -name "*.log" -mtime +30 -delete
Use xargs safelyfind . -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 -ls

Find backups left in public_html

find /home/user/public_html -type f \( -name "*.zip" -o -name "*.tar.gz" -o -name "*.sql" -o -name "*.bak" \) -ls

Find 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 -ls

Safety tips

  • Quote wildcards, for example "*.php", so the shell does not expand them before find runs.
  • Use -ls before destructive actions.
  • Prefer -delete only after the path and tests are very specific.
  • Use \( ... \) around grouped OR conditions.
  • Remember that -mtime +30 means older than 30 days, while -mtime -30 means newer than 30 days.
Real workflows

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 -print

Find writable files

find /home/user/public_html -type f -perm /022 -ls

Find empty files

find . -type f -empty -print
Preview first. Add actions like -delete only after the non-destructive command shows exactly what you expect.
Example output

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
FAQ

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.