Find difference with mtime - and +

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 days1 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.


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.

Tags:

Linux

Bash

Find