Article View: comp.unix.shell
Article #392Re: Time-stamping files
From: Janis Papanagnou
Date: Tue, 17 Nov 2026 06:55
Date: Tue, 17 Nov 2026 06:55
100 lines
5981 bytes
5981 bytes
On 2026-11-17 01:01, Keith Thompson wrote:
> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
>> Occasionally I'm downloading a series of files, be it episodes of
>> films, chapters of documents, etc., and I'm numbering the files with
>> a name indicating the document and containing a sequence number 1..N
>> and I want them also stored with ascending file system time-stamps.
>> Given that I trigger my downloads in parallel I have to 'touch' the
>> files in the correct order afterwards. So far the use case.
>>
>> What I lazily did was, say, touch name*.pdf but while the shell's
>> file expansion lists sequentially name1.pdf name2.pdf ... name8.pdf
>> the 'touch' command seems to _operate_ arguments in *reverse* order.
>>
>> It's no biggie, but I had been wondering about that behavior. I'd at
>> least have expected an option available with 'touch' to control that,
>> or that the files are handled sequentially as provided as arguments.
>
> I haven't been able to reproduce this behavior on my system (Ubuntu).
>
> I built coreutils 9.4 from source and ran the resulting "touch" command
> with 100 arguments. "stat" shows the timestamps (mtime) increasing in
> command line order. The timestamp increases in increments of 1
> millisecond, so multiple files have the same timestamp, in groups of 14
> or 15 files.
>
>> I had thus written my own 'touchlist' script/hack to "fix" that. But
>> I'd be curious about thoughts concerning that behavior of 'touch' (or
>> alternative approaches).
>
> If it were a problem, I'd probably just type
>
> for file in name*.pdf ; do touch "$file" ; done
>
> perhaps with a "sleep" if I want to ensure unique timestamps
> (I get 1-2 millisecond differences without a sleep on my system).
It's unfortunately not guaranteed that you get different timestamps
that way. (On my system I get regularly clashes, i.e. files with the
same timestamps.) And 'sleep' I'd avoid for reasons given; certainly
if we can comparably simply avoid these (as I've done with my script).
> There's nothing wrong with writing a script do that, but I probably
> wouldn't bother.
>
> My system (with an ext4 filesystem) stores timestamps with nanosecond
> precision (but not, apparently, nanosecond accuracy). Others
> might not. IIRC, FAT32 has 2-second precision.
Given (also) my response to Geoff with the data from 'stat' and the
"8 ns jump" of the timestamp I'm still puzzled what is going on here.
(I quote it for completeness here, and *fixed* a crucial observation
error I made; the difference is *not* 8 ns but rather already in the
ms range, .2111... vs. .2121..., which I previously missed to see.)
$ touch 6 7 8 9
and the 'stat' command for these four files shows
2026-11-16 16:13:47.211143078 +0100 6 ___________ gap of
2026-11-16 16:13:47.212143070 +0100 7 ~1 ms
2026-11-16 16:13:47.212143070 +0100 8
2026-11-16 16:13:47.212143070 +0100 9
$ ls -ltr 6 7 8 9
-rw-rw-r-- 1 xyz xyz 0 Nov 16 16:13 6
-rw-rw-r-- 1 xyz xyz 0 Nov 16 16:13 9
-rw-rw-r-- 1 xyz xyz 0 Nov 16 16:13 8
-rw-rw-r-- 1 xyz xyz 0 Nov 16 16:13 7
A couple things are to observe here. Files 7, 8, and 9 have the same
timestamp but are ordered sequentially anyway. "What" is responsible
for the listing order given in "ls -t" (and "ls -tr") that they are
presented in an order that cannot be explained by the timestamp alone.
Then, between _groups_ of identical timestamps, here {6} and {7, 8, 9}
respectively there is an ordering (i.e. {6} comes before {7, 8, 9}).
So one question is whether files with the same timestamps will group
correctly "in the order of the arguments" (POSIX) but only while the
timestamps are incidentally unequal.
And the new question arises - which component is responsible, if not
'touch' - and whether the file system might also play a role here.
(My file system is ZFS, if that matters.)
While I think there's a point in Kaz' view
"It should be required to touch all files passed as arguments in
the same invocation to the same timestamp."
I consider it nonetheless sensible to have a visible differentiation
(as POSIX seems to require) in case we explicitly want 'ls' by time.
Given all that I think that my scripting approach is sensible, to
give all files of my single touch call the same timestamp [with sec
resolution] and differentiate them anyway by setting the sub-seconds
for a visible ordering by time. (Where using explicit 'sleep' calls
I think is, for various reasons, not a good choice.)
Now, in which order does 'ls -t' sorts a set of files which have the
property of carrying the _same timestamp_ then; by name?
Janis
Technical Details
Message-ID:
<11dgtp9$34tb9$3@dont-email.me>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!.POSTED!not-for-mailReferences:
<11d957u$1fnqs$1@dont-email.me> <11dg5gc$3vgth$3@kst.eternal-september.org>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!.POSTED!not-for-mail From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.unix.shell Subject: Re: Time-stamping files Date: Tue, 17 Nov 2026 07:55:37 +0100 Organization: A noiseless patient Spider Lines: 100 Message-ID: <11dgtp9$34tb9$3@dont-email.me> References: <11d957u$1fnqs$1@dont-email.me> <11dg5gc$3vgth$3@kst.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 17 Nov 2026 06:55:38 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3306857"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+v7Fm2jSNP8iIzLoPZ3BiD"; posting-host="5fa259b994673009c101264237236da1" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:NvUBc8JsqtWokma2SS5y++0L368= sha256:p8a1/tjCaKh+2wzrucwXBneMMP7ie26OE6Do7JZvtTM= sha1:KAvl4j94cRyfo5dY95WQ36Du1I8= sha256:t2QoHUTx6wxbE2H5z+Dnl2q+5cIZPx4fge2qOFlmavg= Content-Language: en-US In-Reply-To: <11dg5gc$3vgth$3@kst.eternal-september.org>