Monday, June 3, 2013

Find command is most powerful command in linux to find files as per our criteria. It is used  not only to search files but also to run different commands on those files. Mostly we are searching files by modification time or access time of that file. So, in this article, we will search files by this two parameters only. We will see mtime and atime in detail with examples.
  • To find files who accessed in last 7 days

To find files whose access time is newer i.e. in last 7 days only. Then we can search those files by following command.

root@hello:~/ctier/examples# find . -type f -mtime -7

This command will be helpful to get only files i.e. type option will help to get files or directories if you put d instead of f then it will search for directories. And mtime i.e. modification time should be last 7 days only then it should be -7 and if you want to do reverse i.e. you need all files whose modification time is 7 days before i.e. do not display the files whose modification time is last 7 days then use +7.

mtime option we can use with  multiple find commands option like –newer, -type, -name, -depth etc.

Examples:
  •  To find files whose access time is within last 7 days only


root@hello:~/ctier/examples# find . -type f -atime -7
  •     To search files whose access time is more than 15 days older


root@hello:~/ctier/examples# find . -type f -atime +15
  •  To search files whose modification time is within last 7 days and till the 3 depth of directory


root@hello:~/ctier/examples# find . –maxdepth 3 -type f  –mtime -7
  •  To search files whose modification time is last 30 days ok but access time should be within last 2 days only


root@hello:~/ctier/examples# find . –maxdepth 3 -type f  –mtime-30 –atime 2

- maxdepth option is available but instead of it, many times we need to use - depth option and it varies from OS to OS.


Find atime and find mtime are two mainly used options with find command. If you need more information or having some doubts regarding this then please write us at: linuxconcepts@gmail.com

Difference between Soft link and Hard link                                 Groupadd/Groupdel Command 
Posted by Machindra Dharmadhikari On 6/03/2013 08:21:00 PM 2 comments

2 comments:

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

    Chitika Ads 2

    Histat

    About

    Enter your email address:

    Delivered by FeedBurner