Tech in a Galagzee, Not So Far Away.
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
| Print article | This entry was posted by Ville Walveranta on 23 February 2009 at 17:13, and is filed under Technical, UNIX. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 1 year ago
Thanks, that was very helpful!
about 1 year ago
Nice!!!!!!