I'm using the following to find all files that are older than a reference file...

find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt

... which works as expected.

However, I want to add a bit of leniency to the time, so that it only finds files that are older than the reference file - a few hours.

For example, if I have a reference file with modification date May 26 11:26, I want to find files that are older than May 26 9:26 (ie, with a 2-hour leniency on the reference file).

In this example, the following would be correct matches...

May 26 7:00
Apr 15 14:00

... and the following should not match...

Jun 13 9:00
May 26 10:00

Ultimately I want to delete all the files that I find, so would love it if find was able to handle this requirement? Otherwise, are there any other alternatives that will allow me to delete these files without being too convoluted?

  • Please, can you clarify if you are looking for 1) files older than the reference file 2hour OR more than 2hour (>=) 2) files that are older that the reference file exactly 2 hour. (=) – lese Nov 6 '15 at 8:52
  • I'm looking for files that are older that the reference file less 2 hours. See the example in my question - in the example, I would want all files that are older than May 26 9:26, so it should also match files with dates May 26 7:00, Apr 15 14:50, ... but not match dates Jun 13 9:00 or May 26 10:00. – wattostudios Nov 9 '15 at 2:30

Try out with this :

find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt -mmin +120 -print

adding the parameter -mmin +120 find command will return only the files older than 2-hour in comparison to referencefile.txt modification date.


mkdir find
touch find/dummyfiles1 find/dummyfiles2 find/dummyfiles3 find/dummyfiles4 find/referencefile.txt
touch -t 8001031305 dummyfiles1 dummyfiles2
find find/ -name "dummyfiles*" ! -newer find/referencefile.txt -mmin +120




  • 1
    You should explain why your solution is different to what the OP is already doing, and how it solves their problem. – cas Oct 29 '15 at 6:33
  • Improved the answer, It was so late in my country : ) – lese Oct 29 '15 at 8:53
  • No, this doesn't do what you claim. This command matches files that are older than referencefile.txt and at least two hours old. Nothing here says “two hours older than the reference file”. – Gilles Oct 31 '15 at 23:00
  • This answer do exaclty what I claim (don't call me storyteller) : "return only the files older than 2-hour"(it's what I'm claiming). Anyway, maybe I missed understood the question. Waiting for a clarification from the OP – lese Nov 6 '15 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.