Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to find files within a date range to the minute. I suppose knowing how to do it to the second might be beneficial one day. Anyhow. I've learned how to use -newermt and even -not -newermt; however, I can't seem to get correct results when I combine them. I found linux examples of using find, but don't think the switches are working on OSX. See the following list of files:

#$ ls -l
total 32
-rw-r--r--  1 testuser  staff  1024 Oct 26 20:12 test1.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 19:00 test1_old.swc
-rw-r--r--  1 testuser  staff  1024 Oct 26 20:12 test2.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 19:00 test2_old.swc
-rw-r--r--  1 testuser  staff  1024 Oct 26 20:12 test3.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 19:00 test3_old.swc
-rw-r--r--  1 testuser  staff  1024 Oct 26 20:12 test4.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 19:00 test4_old.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 20:11 test5.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 20:13 test6.swc
-rw-r--r--  1 testuser  staff     0 Oct 26 19:00 timestamp.tmp

I would expect the following command to return test1.swc through test4.swc; however, notice that it returned test6.swc:

#$ find . -newermt '2010-10-26 20:11' -a -not -newermt '2010-10-26 20:13'

I thought the minute for the -not condition was off so I tried the following, but it returned nothing:

#$ find . -newermt '2010-10-26 20:11' -a -not -newermt '2010-10-26 20:12'

I've concluded that I'm not properly combining the -newermt and -not -newermt switches. Any advice on how to correct this?

share|improve this question
up vote 3 down vote accepted

Your syntax looks correct. How did you create these files. I have seen the wrong return when just using touch to update the date.

In BSD -a is not necessary, and I tend to use ! instead of -not (personal perference)

When searching for command help remember that you want to search BSD, because there are some differences I use FreeBSD man pages

Remember that on the file there is something beyond minutes, so if you want the first second then you need to mark it. I set up a structure like yours and when I added the :00 for the seconds I could get the same results that you got, where it didn't make sense. so I did an ls -lT and was able to see the seconds on the file and then ran the find command and got my expected results it looks like by default the ! or -not sets the seconds to 59 so it includes the entire minute.

#$ find . -newermt "2010-10-26 20:11:00" ! -newermt "2010-10-26 20:13:00"
share|improve this answer
That also returns nothing on my fileset. I created the files using touch -mt. The last file, test6.swc was created a while later than the others, but with the following: touch -mt 201010262013 test6.swc Still it is listed in the result set if I use: find . -newermt "2010-10-26 20:11" ! -newermt "2010-10-26 20:13", which hints that maybe even the syntax you suggested is failing (I don't think the time should be 20:12 on the '!' condition, I think it should be 20:13) – Michael Prescott Oct 27 '10 at 4:17
Sorry I edited the post, I had two version I was working on and copied the wrong one in. – Robert Leckie Oct 27 '10 at 4:26
Thanks for the help. Using your example and a new fileset I found the problem. I created a new fileset with touch -mt 201010262010 test1_new.swc test2_new.swc test3_new.swc test4_new.swc and touch -mt 201010262011 test5_new.swc. Then I executed the command: find . -newermt "2010-10-26 20:10" ! -newermt "2010-10-26 20:11", which returned just the test5_new.swc, instead of the desired 1 through 4. However, when I used, find . -newermt "2010-10-26 20:09:59" ! -newermt "2010-10-26 20:10:59" I got the results I expected. – Michael Prescott Oct 27 '10 at 4:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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