I know there is this option for unix’s find command:
find -version
GNU find version 4.1
-newer file Compares the modification date of the found file with that of
the file given. This matches if someone has modified the found
file more recently than file.
Is there an option that will let me find files that are older than a certain file. I would like to delete all files from a directory for cleanup. So, an alternative where I would find all files older than N days would do the job too.
You can use a
!to negate the -newer operation like this:If you want to find files that were last modified more then 7 days ago use:
UPDATE:
To avoid matching on the file you are comparing against use the following:
UPDATE2 (several years later):
The following is more complicated, but does do a strictly older than match. It uses
-execandtest -otto test each file against the comparison file. The second-execis only executed if the first one (thetest) succeeds. Remove theechoto actually remove the files.