What is the difference with mtime
's -
and +
switches as both are not bringing back the results I need?
I'm looking to delete all files older than 5 days:
find /mnt/sdb1/tmp/ -type f -mtime +5 -exec ls {} \;
find /mnt/sdb1/tmp/ -type f -mtime -5 -exec ls {} \;
I've changed the output to ls
to compare the results.
Best Answer
From
find
's man page:So,
-mtime +5
will find those files last modified more than 5*24h ago and-mtime -5
will find those files last modified less than 5*24h ago. To delete files that are older than 5 days1 you would do:If this is not returning the result you want, there may be a problem with the timestamp. Is it correctly reported for the files in question? If this is an external USB drive, the files may have been created on another machine and have a different timstamp than what you expect.
1Note that the unit here is a day, 24 hours. So more than 5 days old means at least 6 days old since the value is always rounded and fractional parts ignored.