Saturday, March 26, 2016

find files from a certain date range in linux

When you need to find a file from a specific range of dates, like a reciept that you know you saved but can't remember where.. You can use the find command along with some parameters to find files newer than a specific date, older or between two dates.

Thanks to the commandlinefu.com article about this.. I'm just basically copying it here for my reference ;)

Using find's -newermt option allows you to get files newer than the specified date. You can get files older than the date by putting a ! before the flag. and if you use both, you can get files within a certain range:

# Get files after Y2K:
find . -type f -newermt "2000-01-01"

# Get files from before June 2012:
find . -type f ! -newermt "2012-06-01"

# Get files between Feb 16, 2016 and Feb 18, 2016
find . -type f -newermt "2016-02-16" ! -newermt "2016-02-18"

No comments :