Unix find -mtime {a negative or postive value}
Asked Answered
P

3

6

What do find -mtime -4 and find -mtime +4 do? I cannot understand the examples given in the man page.

Preponderate answered 30/12, 2014 at 6:57 Comment(0)
D
9

As per man page:

-mtime n
    File’s  data was last modified n*24 hours ago.  See the comments
    for -atime to understand how rounding affects the interpretation
    of file modification times.

The argument to -mtime is interpreted as the number of whole days in the age of the file. -mtime +n means strictly greater than, -mtime -n means strictly less than.

So in your case,

-4 meaning less than 4 days.
+4 meaning more than 4 days i.e. 4*24 hours.

Definiendum answered 30/12, 2014 at 7:6 Comment(1)
Thanks! I got my answer!Preponderate
M
11

Well, I can.

-mtime n

File's data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times

find . -mtime 0   # find files modified between now and 1 day ago
                  # (i.e., within the past 24 hours)
find . -mtime -1  # find files modified less than 1 day ago
                  # (i.e., within the past 24 hours, as before)
find . -mtime 1   # find files modified between 24 and 48 hours ago
find . -mtime +1  # find files modified more than 48 hours ago
Malti answered 30/12, 2014 at 7:1 Comment(3)
Thanks for the solution! But I know this thing. I wanted to know if I give any negative value then what does it mean?Preponderate
Nope! I used-- find . -mtime -4 & find . -mtime +4 .They are giving different results.Preponderate
you are absolutley right, sorry and thx for correcting me, after such a long time.Malti
D
9

As per man page:

-mtime n
    File’s  data was last modified n*24 hours ago.  See the comments
    for -atime to understand how rounding affects the interpretation
    of file modification times.

The argument to -mtime is interpreted as the number of whole days in the age of the file. -mtime +n means strictly greater than, -mtime -n means strictly less than.

So in your case,

-4 meaning less than 4 days.
+4 meaning more than 4 days i.e. 4*24 hours.

Definiendum answered 30/12, 2014 at 7:6 Comment(1)
Thanks! I got my answer!Preponderate
O
0

None of my searches - be they for "negative", "mtime", "strictly" - found the normative text in the man page, but it's there, oy, a quarter of the way through:

   Numeric arguments can be specified as

   +n     for greater than n,

   -n     for less than n,

   n      for exactly n.

But who needs the man page when Google's top match is Stack Overflow, where @SMA and @wgitscht had already given the correct answer? Well, it's nice to know it's de jure and not a happy accident.

Ortensia answered 6/11, 2020 at 16:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.