Find -Mtime Not Working

Find -Mtime Not Working

I tried all the suggestions in the article: Script that delete files after 5 days

When I run find without the -mtime parameter it finds the files I am looking for. When I add -mtime +2, nothing is returned. I know there are files of the appropriate date(s) in the directory I am looking in with the find command.

2

1 Answer

From man find:

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

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

but see also:

  -daystart
          Measure  times  (for  -amin,  -atime,  -cmin,  -ctime,  -mmin, and -mtime) from the
          beginning of today rather than from 24 hours ago.  This option only  affects  tests
          which appear later on the command line.

In summary, use find -mtime +1 to find 2 day old files.

Your Answer

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

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.