0

I was trying to use find with -mtime +1 to find all directories older than 24 hours but having issues getting this done. I understand that using -mtime +n should remove n*24 hours of data but it seems to only find one folder to remove - 2019-07-05. Why doesn't it also offer the 2019-07-06 folder?

From find man page:

-mtime n
File's  data  was  last modified n*24 hours ago.  

Example:

[user@craptaindee mysql] find /some/folder/mysql/ -type d -mtime +1
/some/folder/mysql/2019-07-05

[user@craptaindee mysql] find /some/folder/mysql/ -type d 
/some/folder/mysql/
/some/folder/mysql/2019-07-07
/some/folder/mysql/2019-07-06
/some/folder/mysql/2019-07-08
/some/folder/mysql/2019-07-05

Here are the timestamps on the folders

drwxr-xr-x 2 root root 4096 Jul  5 23:40 2019-07-05
drwxr-xr-x 2 root root 4096 Jul  6 23:40 2019-07-06
drwxr-xr-x 2 root root 4096 Jul  7 23:40 2019-07-07
drwxr-xr-x 2 root root 4096 Jul  8 13:00 2019-07-08

I was able to complete my task using -mmin but I don't understand why -mtime doesn't act as I would expect from the man page. Also, -ctime doesn't show the other directory either.

EDIT: I completed these tests just before making this post in the early afternoon in the Pacific Timezone at roughly ~13:00 on July 08 2019.

2
  • "roughly ~13:00 on July 08 2019" – So this is an exact duplicate of the linked question. In your case files "older than 2 days" are from before ~13:00 on July 06 2019. The file 2019-07-06 doesn't qualify because of its later hour. Jul 9 '19 at 18:03
  • Got it -- then I should use +0 instead of +1. Thanks @Kancer
    – saleetzo
    Jul 9 '19 at 18:22
1

Try adding daystart with find command

find /path -type d -daystart -mtime +1
1
  • This might have part of the answer im looking for! man find shows -daystart "Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and -mtime) from the beginning of today rather than from 24 hours ago."
    – saleetzo
    Jul 9 '19 at 18:12

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