Find by date http://www.cyberciti.biz/faq/howto-finding-files-by-date/ find . -mtime 0 # find files modified between now and 1 day ago # (i.e., within the past 24 hours) find . -mtime -1 # find files modified less than 1 day ago # (i.e., within the past 24 hours, as before) find . -mtime 1 # find files modified between 24 and 48 hours ago find . -mtime +1 # find files modified more than 48 hours ago find . -mmin +5 -mmin -10 # find files modified between # 6 and 9 minutes ago Find Files By Access, Modification Date / Time http://content.hccfl.edu/pollock/unix/findcmd.htm [a] access (read the file's contents) - atime [b] change the status (modify the file or its attributes) - ctime [c] modify (change the file's contents) - mtime You can search for files whose time stamps are within a certain age range, or compare them to other time stamps. You can use -mtime option. It returns list of file if the file was last accessed N*24 hours ago. For example to find file in last 2 months (60 days) you need to use -mtime +60 option. -mtime +60 means you are looking for a file modified 60 days ago. -mtime -60 means less than 60 days. -mtime 60 If you skip + or - it means exactly 60 days. So to find text files that were last modified 60 days ago, use $ find /home/you -iname "*.txt" -mtime -60 -print Display content of file on screen that were last modified 60 days ago, use $ find /home/you -iname "*.txt" -mtime -60 -exec cat {} \; Count total number of files using wc command $ find /home/you -iname "*.txt" -mtime -60 | wc -l You can also use access time to find out pdf files. Following command will print the list of all pdf file that were accessed in last 60 days: $ find /home/you -iname "*.pdf" -atime -60 -type -f List all mp3s that were accessed exactly 10 days ago: $ find /home/you -iname "*.mp3" -atime 10 -type -f There is also an option called -daystart. It measure times from the beginning of today rather than from 24 hours ago. So, to list the all mp3s in your home directory that were accessed yesterday, type the command $ find /home/you -iname "*.mp3" -daystart -type f -mtime 1 Where, -type f - Only search for files and not directories -daystart option The -daystart option is used to measure time from the beginning of the current day instead of 24 hours ago. Find out all perl (*.pl) file modified yesterday, enter: $ find /nas/projects/mgmt/scripts/perl -mtime 1 -daystart -iname "*.pl" You can also list perl files that were modified 8-10 days ago, enter: To list all of the files in your home directory tree that were modified from two to four days ago, type: $ find /nas/projects/mgmt/scripts/perl -mtime 8 -mtime -10 -daystart -iname "*.pl" Unix Shell: find files by a date range http://my.galagzee.com/2009/02/23/unix-shell-find-files-by-a-date-range/ I needed to restore some files from an archive on UNIX, but only the files of a particular date-range were needed. It took a few moments to find and figure out how I could easily extract files older than a particular date, or files from a particular date-range. This is how: Create a perimeter file, like so: touch -t yyyymmddHHMM marker_date List files older than the marker_date: find . -type f ! -newer marker_date -ls Of course, instead of `-ls’ parameter (to list), you can use `-print’ and a pipe to xargs to, for example, delete the selected files, etc. Likewise, for a range of dates: Create the perimeter files: touch -t yyyymmddHHMM range_start touch -t yyyymmddHHMM range_end List the files between the range dates: find . -type f -newer range_start ! -newer range_end -ls |
Unix >