2020-01-05 17:08:24 +0100, Ingo Schwarze:
[...]
> But note that the POSIX standard
> 
>   https://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html
> 
> contradicts itself:
[...]
>   The following command:
>     find / \( -name tmp -o -name '*.xx' \) -atime +7 -exec rm {} \;
>   removes all files named tmp or ending in .xx that have not been
>   accessed for seven or more 24-hour periods.

Hi,

I did report that problem last year:
http://austingroupbugs.net/view.php?id=1259
and it will be fixed in the next technical corrigendum

[...]
> FreeBSD and NetBSD both have the same "rounded up" language in the
> manual page and the same "+ SECSPERDAY - 1" in the -mtime
> implementation, which appears to contradict the claim "The description
> is also different in terms of the exact timeframe for the n case
> (versus the +n or -n), but it matches all known historical
> implementations" in the POSIX RATIONALE.
> 
> Is this really the mess it seems to me now, with all BSDs consistently
> disagreeing with POSIX?  I really hope i'm missing something here...
> 
> If people here agree that BSD and POSIX contradict each other,
> should i ask about that on the Austin Group mailing list?
[...]

At the time POSIX.2 was written (early 90s), BSDs would probably
still have been using the Unix v7 code which behaved like POSIX
requires. The change in BSD was introduced when find was replaced
by the one from Cimarron Taylor
https://github.com/dspinellis/unix-history-repo/commit/1b62b84328735f04e31cb066f4e1fe0c6fd0061a
for BSD 4.3 Net/2.

Note that from a user point of view, it can be quite confusing.
You need -mtime +6 to get files that are over 7 days old.
Everybody gets it wrong. The POSIX spec in the example above,
most tutorials on find, even the GNU find documention but
it's probably the best we can get at the moment without
introducing a new interface.

-mtime +6: over 7 days old
-mtime  6: between 6 and 7 days old
-mtime -6: less than 6 days old.

zsh follows the POSIX find rules for its glob qualifiers.
*(m+3) same as -mtime +3 (over 4 days old).

FreeBSD has a much better interface IMO when you use suffixes.

-mtime +6d: over 6 days old
-mtime -6d: less than 6 days old
-mtime  6d: exactly 6 days old to the exact nanosecond which is
            pointless, but who cares. If you want the equivalent
            of POSIX -mtime 6, you can use -mtime +6d -mtime -7d
            which is more intuitive.

And it supports other suffixes (-mtime +4m better than GNU's -mmin +3).

(I don't remember if it does the same for -size -1M or if it
behaves like GNU find/zsh (rounds up to the next M before
comparing, so only finds files of size 0 here)).

-- 
Stephane

Reply via email to