Tuesday, May 26, 2009

Finding files in Unix/Linux between a date range...

From http://my.galagzee.com

==========================

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

0 comments: