help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should -et be available?


From: Dennis Williamson
Subject: Re: Should -et be available?
Date: Mon, 25 May 2020 08:55:40 -0500

On Mon, May 25, 2020, 8:24 AM Peng Yu <address@hidden> wrote:

> On 5/24/20, Andreas Kusalananda Kähäri <address@hidden> wrote:
> > On Sun, May 24, 2020 at 07:00:43PM -0400, Chris F.A. Johnson wrote:
> >> On Sun, 24 May 2020, Peng Yu wrote:
> >>
> >> > I don't find a way to test whether two files are at the same time.
> >> > Should there be a switch for this comparison given -nt and -ot are
> >> > available? Thanks.
> >> >
> >> >       file1 -nt file2
> >> >              True if file1 is newer (according to modification date)
> >> > than file2, or if file1 exists and file2 does not.
> >> >       file1 -ot file2
> >> >              True if file1 is older than file2, or if file2 exists
> >> > and file1 does not.
> >>
> >>  Use both tests. If it is neither older nor newer, then it is the same.
> >
> >
> > Both tests would also be false if neither file exists, so you would have
> > to supplement the tests with at least one -e test.
>
> Yes. Therefore, a -et is better to be added. Otherwise, it can be
> cumbersome to perform the equal timestamp test.
>
> --
> Regards,
> Peng
>

With an OS/filesystem which supports subsecond file modification times
neither -ot or -nt may be true if the seconds are the same (so far as
expected) but the fractional seconds are different (so the file times are
not actually equal). This may not be what you expect.

 $ cat /etc/lsb-release
 DISTRIB_ID=Ubuntu
 DISTRIB_RELEASE=18.04
 DISTRIB_CODENAME=bionic
 DISTRIB_DESCRIPTION="Ubuntu 18.04.3 LTS"
 $ <CTRL-X><CTRL-V>
 GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
 $ # touch with delay - modification times not equal
 $ touch test1; sleep .001; touch test2; stat --format='%y %n' test1 test2
 2020-05-25 08:38:26.209032136 -0500 test1
 2020-05-25 08:38:26.221031929 -0500 test2
 $ [[ test1 -ot test2 ]] && echo older
 $ [[ test1 -nt test2 ]] && echo newer
 $ # touch with no delay - modification times equal
 $ touch test1 test2; stat --format='%y %n' test1 test2
 2020-05-25 08:40:52.680722254 -0500 test1
 2020-05-25 08:40:52.680722254 -0500 test2
 $ [[ test1 -ot test2 ]] && echo older
 $ [[ test1 -nt test2 ]] && echo newer
 $

>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]