Article View: comp.unix.shell
Article #408Re: Time-stamping files
From: Keith Thompson
Date: Wed, 18 Nov 2026 23:19
Date: Wed, 18 Nov 2026 23:19
80 lines
4879 bytes
4879 bytes
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
> On 2026-11-17 22:40, Keith Thompson wrote:
[...]
>> I don't think you had said that you wanted unique timestamps.
>
> I wanted _ascending_ timestamps.
>
> The point is that with spurious 'sleep' delays you could get strange
> results; e.g. in the meantime downloaded files could get in-between.
> So the dates should be close together, and since I can do my counts
> in the sub-seconds parts the *nice* _side-effect_ is that the set of
> files will carry the same timestamp.
>
>> What you get with `touch 0 1 2` is that 0 is no newer than 1 and
>> 1 is no newer than 2 (where "newer" is defined by the mtime). Any
>> two, or all three, can have the same timestamp if they're touched
>> more quickly than the clock updates.
>
> Yes, they can be the same or different (as said before; and see my
> previously posted 'stat' output example).
Hmm. I would interpret "_ascending_ timestamps" to mean a < b < c.
If all you need is a <= b <= c, I'd describe that as non-descending
timestamps.
>> I think you were observing the output of `ls -tr` and *incorrectly*
>> assuming that it indicated that, for example, 0 is newer than 1,
>> when in fact 0 and 1 have the same timestamp, but `ls -tr` uses
>> some other criterion to decide how to sort them.
>
> Yes and no. As seen in my previously posted data the files with the
> same internal timestamp are ordered, of course not by the timestamp
> but by something else; may it be the name, or the physical position
> in the directory, or whatever; that order is *also* affected by the
> '-r'. So me have some mixture, primary search criterion is the time,
> and the secondary criterion isn't clear to me.
Just to be clear, there are no separate internal and external
timestamps. A file's mtime is, on my system, stored with nanosecond
resolution. `ls -t` or `ls -tr` uses the full nanosecond-precise
timestamp as the primary sort key (and the name as the secondary
key when two files have the same precise mtime). `make` uses the
full precision timestamp when deciding which of two files is newer.
And so on.
`ls -l` simply doesn't display the fractional part of the mtime.
`ls -l --full-time` does, as does `stat`.
>> Reading the GNU coreutils ls documentation, I don't see any mention
>> of how `ls -tr a b` orders its output when a and b have the same
>> timestamp. I speculate that if the timestamps are the same, it
>> falls back to locale-specific alphabetical sorting -- and since
>> the `-r` (`--reverse`) option was given, it sorts b before a.
>> Someone could examine the source code.
>
> Yes, that's one possibility. (It's just not transparent which one
> it actually is.)
As discussed elsethread, that behavior seems to be required by Posix.
It would be nice, I suppose, if you could use the timestamp, oldest
first, as the primary key, and the name, not reversed, as the
secondary key, but ls doesn't have options to do that. (And I'm
not suggesting it should.)
[...]
>> POSIX specifies the `-d` option to touch and allows fractional
>> seconds, but it doesn't specify how many digits are significant.
>
> Yes, that's what I've been using in my script. - I suppose that the
> supported resolution may depend on the filesystem.
In particular, FAT32 has 2-second resolution, so if you try to create
1000 files with distinct timestamps, they'll range over more than 8
minutes.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Technical Details
Message-ID:
<11dlbqf$1p00u$3@kst.eternal-september.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!kst.eternal-september.org!.POSTED!not-for-mailReferences:
<11d957u$1fnqs$1@dont-email.me> <11dg5gc$3vgth$3@kst.eternal-september.org> <11dgtp9$34tb9$3@dont-email.me> <11dihk2$q4aj$1@kst.eternal-september.org> <11djl65$s03n$2@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!kst.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson <Keith.S.Thompson+u@gmail.com> Newsgroups: comp.unix.shell Subject: Re: Time-stamping files Date: Wed, 18 Nov 2026 15:19:43 -0800 Organization: None to speak of Lines: 80 Message-ID: <11dlbqf$1p00u$3@kst.eternal-september.org> References: <11d957u$1fnqs$1@dont-email.me> <11dg5gc$3vgth$3@kst.eternal-september.org> <11dgtp9$34tb9$3@dont-email.me> <11dihk2$q4aj$1@kst.eternal-september.org> <11djl65$s03n$2@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Wed, 18 Nov 2026 23:19:43 +0000 (UTC) Injection-Info: kst.eternal-september.org; logging-data="1867806"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19FvYlTyIu1mDv3FhCbxt88"; posting-host="38a0272be55613828d7088b9a912db21" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:G9wjhRMPO5PSrMb2L2nesm+rN2E= sha256:Y3ttAc7w0fm4uwBjkrbfbPYEzLQnVZAq0+WZSQ3I7ro= sha1:rpXLZlQc/2xcdLQsZE7mnK6CH5A= sha256:DFnPSjrzM0b+Ip840D4ddKc+anbrQ4yEvNdU6POZipg=