0

I have two different linux based systems where the find command doesn't seem to be working as expected.

I have a directory. In it I run...

ls -l

and the system returns...

drwxr-xr-x 2 panopticon36 panopticon36 4096 May 22 12:28 folder1
drwxr-xr-x 2 panopticon36 panopticon36 4096 May 22 12:28 folder2
drwxr-xr-x 2 panopticon36 panopticon36 4096 May 22 12:25 folder3
drwxr-xr-x 2 panopticon36 panopticon36 4096 May 24 09:52 folder4

today is 5/24/17.

In the same directory, if I run...

find . -mtime +1 -type d

the system returns nothing.

From my understanding, the find command should find all directories "-type d" in the current directory "." that are more than 1 day old "-mtime +1". So...

folder1
folder2
folder3

should all be listed to my understanding. Two systems under my care are exhibiting this behavior. Am I doing something incorrectly or missing something? Could something be modifying directories in such a way that ls -l does not reflect the correct date modified? Is there something else I could attempt to troubleshoot the issue? All help is welcome.

1 Answers1

1

Due to the weird way the mtime is rounded up, +1 means "48 hours or more". This is documented on the man page.

The way to memorize it is to start from the most basic use: -mtime 1 which means that file was accessed 24 hours ago plus any fraction (for example 24+23 hours would also match). From this follows "logically" what +1 and -1 mean.

kubanczyk
  • 13,502
  • 5
  • 40
  • 55
  • Yeah but folders 1 through 3 were all modified (May 22 according to ls -l) 2 days ago, so +1 should list them. I see what you are saying and that would make sense if the folders were last modified May 23rd. – Dean Taylor May 24 '17 at 16:42
  • Only if you have run `find` on May 24, 12:28 or later. Have you? And it could be a timezone-related issue like [this question](https://serverfault.com/questions/207792/find-mtime-does-not-work-as-expected-on-files-with-different-timezones?rq=1). – kubanczyk May 24 '17 at 16:45
  • I'm sorry. You are correct. +1 indicates files a full 48 hours later than the time at which the command is run. Thank you for the clarification. I appreciate it. – Dean Taylor May 24 '17 at 17:18
  • @DeanTaylor You may want to look at `-daystart` if you'd rather count calendar days than seconds – Tavian Barnes Jun 29 '17 at 20:56