Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Can someone explain the difference with mtime - and + switch as both are not bringing back the results I need. I'm looking to delete all files older then 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

Thanks

share|improve this question

2 Answers 2

up vote 2 down vote accepted

From find's man page:

    Numeric arguments can be specified as

   +n     for greater than n,
   -n     for less than n,
    n     for exactly n.

  -mtime n
          File's data was last modified n*24 hours ago.  See the comments for 
          -atime to understand how rounding  affects  the  interpretation  of
          file  modification times.

   -atime n
          File was last accessed n*24 hours  ago.   When  find  figures  out  
          how  many 24-hour  periods  ago  the  file  was  last  accessed, any 
          fractional part is ignored, so to match -atime +1, a file has to have 
          been accessed at least two days ago.

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 days you would do:

find /mnt/sdb1/tmp/ -type f -mtime +5 -exec rm {} \;

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.

share|improve this answer

-mtime +5 should show you all files modified 5 days and before (6, 7, ...), while -5 should show the ones modified today up to 5 days ago.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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