Linux Search and Find

Finding files and searching content

Find Files

find . -name *.txt # find by name
find /path -type f # find files only
find /path -type d # find directories only
find . -name file* -delete # find and delete

Find by Size

find . -size +100M # files larger than 100MB
find . -size -1M # files smaller than 1MB

Find by Time

find . -mtime -7 # modified in last 7 days
find . -atime +30 # accessed more than 30 days ago

Locate

locate filename # fast file search (uses database)
updatedb # update locate database

Search Content

grep pattern file # search in file
grep -r pattern /path # recursive search
grep -i pattern file # case-insensitive
grep -n pattern file # show line numbers
grep -v pattern file # invert match

Which and Whereis

which command # locate command executable
whereis command # locate binary, source, and man pages