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:

  1. Create a perimeter file, like so:
    touch -t yyyymmddHHMM marker_date

  2. 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:

  1. Create the perimeter files:
    touch -t yyyymmddHHMM range_start
    touch -t yyyymmddHHMM range_end

  2. List the files between the range dates:
    find . -type f -newer range_start ! -newer range_end -ls

, ,

  1. #1 by Henrique on 26 March 2009 - 07:48

    Thanks, that was very helpful!

  2. #2 by Flex on 05 May 2009 - 17:35

    Nice!!!!!!

(will not be published)