Linux: using find to locate files older than <date>
Solution 1:
No, you can use a date/time string.
From man find
:
-newerXY reference
Compares the timestamp of the current file with reference. The reference argument is normally the name of a file (and one of its timestamps is used for the comparison) but it may also be a string describing an absolute time. X and Y are placeholders for other letters, and these letters select which time belonging to how reference is used for the comparison.a The access time of the file reference B The birth time of the file reference c The inode status change time of reference m The modification time of the file reference t reference is interpreted directly as a time
Example:
find -newermt "mar 03, 2010" -ls
find -newermt yesterday -ls
find -newermt "mar 03, 2010 09:00" -not -newermt "mar 11, 2010" -ls
Solution 2:
Not directly related to question, but might be interesting for some that stumble here.
find command doesn't directly support -older parameter for finding files older than some required date, but you can use negate statement (using accepted answer example):
touch -t 201003160120 some_file
find . ! -newer some_file
will return files older than provided date.
Solution 3:
If you have only '-newer file' then you can use this workaround:
# create 'some_file' having a creation date of 16 Mar 2010:
touch -t 201003160120 some_file
# find all files created after this date
find . -newer some_file
man touch:
-t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time
Assuming that your touch has this option (mine is touch 5.97).
Solution 4:
find <dir> -mtime -20
this find command will find files modified within the last 20 days.
- mtime -> modified (atime=accessed, ctime=created)
- -20 -> lesst than 20 days old (20 exactly 20 days, +20 more than 20 days)
You acan add additional limitations like:
find <dir> -mtime -20 -name "*.txt"
the same as before, but only finds files ending with '.txt'.
Solution 5:
Just to add on - you may even use two newermt arguments to search in a time interval:
find ! -newermt "apr 01 2007" -newermt "mar 01 2007" -ls
to find all files from march 2007.