linux find usefuls

By name:

find -name foo     
# with the name foo in the current directory tree

By Time

find -mtime 0      
# modified in the last day, current directory tree

By Size

find . -size +500000 -print       
# find large files (over 500MB). 

By wildcard name

find . -name 'c*_g*' -type f      
# with c*_g* in the current directory tree, ignore dirs, etc.

Ignore errors

find / -name foo 2>/dev/null      
# with name foo, from root, ignore access error messages

Current directory recently

find -type f -mmin 15 -prune      
# current directory only, last 10 minutes modified

Current directory by wildcard

find . -maxdepth 1 -name "help*"  
# Find any file that start with the word help, current directory only

Find and ls

find . -name "*.pl" -exec ls -ld {} ;     
# ls the results

Find and delete

find . -name "*.tmp" -print | xargs rm –f  
# Delete temporary files

Find and print directory

find . -exec grep "lass" '{}' ; -print    
# Search file(s) for the string

Find and search for string

find . –name "*.txt" –print | xargs grep "Except"  
# Find *.txt files with the string

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s