Playing with Find command options

Finding files with name using -name option

find /home/webxpert -name “*.c”

 find /home/webxpert -name webxpert.conf

if you want to find case specific(Upper/lower) you can use -iname

find /home/webxpert -iname Webxpert.conf

 Finding files owned by a user using -user option

 find / -user webxpert

 Finding files based on access time using -atime option

find /home/webxpert -atime +3 ( Find files which accessed more than 3 days ago) find /home/webxpert -atime -3 (Find files which accessed less than 3 days ago ) find /home/webxpert -atime 3 (Find files which accessed exactly 3 days ago )

Finding files based on modification time using -mtime option

find /home/webxpert -mtime +3 ( Find files which modified more than 3 days ago) find /home/webxpert -mtime -3 (Find files which modified less than 3 days ago ) find /home/webxpert -mtime 3 (Find files which modified exactly 3 days ago )

Finding files based on status change(For example using “chmod” change status of a file) using -cname

find /home/webxpert -ctime +3 ( Find files which status changed  more than 3 days ago)

find /home/webxpert -ctime -3 (Find files which status changed  less than 3 days ago )

find /home/webxpert -ctime 3  (Find files which status changed  exactly 3 days ago )

Find and execute another command

find /home/webxpert -name ‘*.conf’ -exec rm {} \;

 Above command will remove  all files end with extension  .conf  from /home/webxpert directory.

Finding based on File Type

 find  /home/webxpert -type f  -atime +5 -exec rm {} \;

Above command will find and remove all “Files” from  /home/webxpert that have not been accessed in at least 5 days.
in type you can use following options

-type filetype, where
 f = regular file
 d = directory
l = symbolic link, etc.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: