19

So, I understand the difference between the three ideas in the title.

  1. atime -- access time = last time file opened

  2. mtime -- modified time = last time file contents was modified

  3. ctime -- changed time = last time file inode was modified

So, presumably when I type something like

find ~/Documents -name '*.py' -type f -mtime 14

will find all match all files ending with .py which were modified in the last 2 weeks. Nothing shows up...

So I try

find ~/Documents -name '*.py' -type f -atime 1400

which should match anything opened within the last 1400 days (ending with .py and having type file) and still nothing.

Am I misunderstanding the documentation? Does it mean exactly 1400 days, for example?

A relevant post:

find's mtime and ctime options

3 Answers 3

20

Yes, -mtime 14 means exactly 14. See the top of that section in the GNU find manual (labelled "TESTS") where it says "Numeric arguments can be specified as [...]":

Numeric arguments can be specified as

+n     for greater than n,

-n     for less than n,

n      for exactly n.

Note that "less than" means "strictly less than", so -mtime -14 means "last modified at the current time of day, 13 days ago or less" and -mtime +14 means "last modified at the current time of day, 15 days ago or more".

1
  • 1
    as I understand it, -mtime -14 means that it's less than 14 full days after the last modified time, compared after the age is truncated to full days. So the file could be e.g. 13.99 days old. I'm not sure if that's what was meant here, or if I read it wrong, but anyway. (I'm also not sure how to parse the "or less" either, I mean, does it refer to the age of the file or the timestamp of the file...?)
    – ilkkachu
    Commented Jul 11, 2022 at 12:43
4

find ~/Documents -name "*.py" -type f -mtime 14 - exactly 14 days ago

find ~/Documents -name "*.py" -type f -mtime +14 - more than 14 days ago

find ~/Documents -name "*.py" -type f -mtime -14 - less than 14 days ago

The rest in your statement seems to be correct.

2

These -*time statements return files which satisfy the following algorithm (where hours is how many hours ago a file was modified):

for

find -mtime n

int(hours/24) == n

find -mtime -n

int(hours/24) < n

find -mtime +n

int(hours/24) > n

So, for example find -mtime 1

will match files 24-47 hours old

find -mtime +0

will match files that are 24 hours old and older

4
  • To be unambiguous about the effect of int( ), I think you need to replace it with either floor( ), ceiling( ) or round( ).
    – crantok
    Commented Apr 26, 2023 at 12:46
  • Also, if -ctime 1 matches files that are 24 to 47 hours old, does that mean that it does not match files that are 47½ hours old? Or do you mean 24 <= hours < 48 ?
    – crantok
    Commented Apr 26, 2023 at 12:53
  • @crantok, the functions that I gave provide all the answers. E.g. $ touch -mt `date -d '-47 hours -50 min' +%m%d%H%M` tmpstamp; $ find -mtime 1 will return ./tmpstamp
    – drgnfr
    Commented Apr 28, 2023 at 11:24
  • If I understand the code in your comment, then find -mtime 1 found a a file that is more than 47 hours old (i.e. it is 47 hours and 50 minutes old), which answers my second question. The functions you gave answer my first question if they are in C because in that language truncation always happens towards zero. Adding a language to the mix that is not in the OP seems like bad form to me.
    – crantok
    Commented Apr 29, 2023 at 12:31

You must log in to answer this question.

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