34

I know I can use this option to find file between particular modified times. But I'm curious about what does this mean?

I used man find | grep newermt trying to find something. But I got no direct content. It seems -newer file and mtime stuff may have relation with it. But I'm not sure..

So, what does -newermt actually mean?

3 Answers 3

39

find(1):

-newerXY reference
          Compares the timestamp of the current file with reference.   The
          reference  argument  is  normally the name of a file (and one of
          its timestamps is used for the comparison) but it may also be  a
          string  describing  an  absolute time.  X and Y are placeholders
          for other letters, and these letters select which time belonging
          to how reference is used for the comparison.

          a   The access time of the file reference
          B   The birth time of the file reference
          c   The inode status change time of reference
          m   The modification time of the file reference
          t   reference is interpreted directly as a time
2
30

find ./ -mtime +n used to get all files older than n days
find ./ -mtime -n used to get all files modified in last n days
Now if you are using 1 in place of n, you will get files modified in the last 24 hours. But what if you want only files from yesterday and not within the last 24 hours? Here newermt comes into the picture.

find ./ -newermt "2016-01-18" ! -newermt '2016-01-19'

will give you all files which are newer than specified date and ! will exclude all files which are newer than the specified date. So the above command will give a list of files which were modified on 2016-01-18.

1
  • I would say "which are newer than specified date, time 00:00:00"
    – Tms91
    Commented Jan 13, 2023 at 10:59
0

Regarding -newermt, natural language is tricky.  You say "newer than", but one should say "newer than or equal to".  Mathematically, this corresponds to the sign ‘≥’, not to ‘>’.

-newermt given-date means file-dategiven-date.

4
  • 1
    Unfortunately, this appears to be wrong. When I do touch file1; sleep 60; touch file2; sleep 60; touch file and then find . -newer file2 (or, equivalently, -newermm file2), I get only file3, not file2. If the test were newer or equal, it would report that the modification time of file2 is equal to itself. Commented Jun 8, 2022 at 1:37
  • I did a more accurate test to check this: 1. touch -t 202209090909 foo; 2. ls -l --time-style=full-iso foo (which shows 2022-09-09 09:09:00.000000000); 3. find -mindepth 1 -maxdepth 1 -name foo -newermt '2022-09-09 09:09:00' yields nothing; but 4. find -mindepth 1 -maxdepth 1 -name foo -newermt '2022-09-09 09:08:59' finds the test file.
    – Walf
    Commented Aug 1, 2022 at 4:34
  • Yes, comments above are true - it is not greater than or equal - it is greater than - but for most real purposes it will work as greater than or equal because if you say -newermt '2022-09-09 09:00' it means newer than 2022-09-09 09:00:00.000000000, which means all times after that will be included. What are the chances that your file is created at time with all zeros - probably zero! So I think comment deserves +1, not -1.
    – blur
    Commented Dec 27, 2022 at 13:11
  • 2
    @blur You're right for the typical case, but this doesn't apply where a timestamp is set explicitly and does not use microsecond resolution, e.g. with touch or when extracting files from an archive that have been published with a particular date.
    – Walf
    Commented Apr 24, 2023 at 2:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .