Entries (RSS)  |  Comments (RSS)

Linux find strangeness

I’ve been using the Unix find command for as long as I can remember, and today I found an interesting inconsistency in the way that the implementation of mtime/atime/ctime searches:

Here’s a few examples of how this works:

find . -mtime 0   # find files modified within the past 24 hours
find . -mtime -1  # find files modified within the past 24 hours
find . -mtime 1   # find files modified between 24 and 48 hours ago
find . -mtime +1  # find files modified more than 48 hours ago
find . -mmin +5 -mmin -10 # find files modifed between 6 and 9 minutes ago

The argument to mtime is n*24 hours. If n is zero, though, things are very different. If you ask find for -mtime 0, you get everything that has been modified more than 24 hours ago, although the posix man page states that it should find files modified within the past 24 hours.

If you use -mtime +0, then you get everything modified between 24 hours ago and the current time. 

This is in  GNU find version 4.1.20, so you might get different results elsewhere.

This drove me nuts today while trying to help an engineer. Be careful when using find!

This entry was posted on Tuesday, May 20th, 2008 at 12:42 pm and is filed under linux, systems administration. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

blog comments powered by Disqus