R-Ts NetWorks

Server the Best

Using find on Linux

Basic search with find:

find /directory -name 'search term'

Search files in subdirectories of current directory:

find . -name 'search term'

Find large files:

find / -type f -size +100000 -exec ls -lh {} \;

Search inside file contents:

find . | xargs grep --color=auto -iR 'search term' *


find . -type f -exec grep -lR 'search term' {} /dev/null \;

Find files modified in certain time period:

find . -name 'search term' -mtime -1 -print

Exclude certain directories in search:

find . -name 'search term' -prune -o -name 'excluded directory1' -prune -o -name 'excluded directory2' -prune -o -type f -print

Find files older than a certain date (2 days in example) & delete:

find . -mtime +2 -exec rm {} \;

Find and replace in files:

find ./* -type f -exec sed -i 's/search term/replacement/g' {} \;

October 13, 2012 - Posted by | Linux | , , ,

No comments yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: