🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #400

Re: Time-stamping files

#400
From: Kaz Kylheku
Date: Wed, 18 Nov 2026 06:19
72 lines
4974 bytes
On 2026-11-17, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
>> 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).
>
> I don't think you had said that you wanted unique timestamps.
>
> 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.

I'd much more readily get behind the requirement that 0, 1 and 2
have identical timestamps. At least, if they are each on a filesystem
supporting the same resolution of timestamp. (That is to say, the
current time is sampled once, and converted into the time stamp format
supported by each of the argument objects, which may cause it to be
truncated differently, but any two objects that are on the same,
or same kind of filesystem should end up with identical modification
times.)

touch has that -r <ref-object> option which can achieve a facsimile
of these requirements, if the script creates a temporary file,
uses it as a reference and then deletes it.

touch without the -r option would ideally behave the same way as with
-r, except using a single sample of the system time as the reference.

The one infelicity in such an requirement is that it's limited by the
argument passing limits. As soon as you use "xargs" to break up a long
touch command line, the all-stamps-same property is lost; you have to
resort to the -r <ref-object> option.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
Technical Details
Message-ID: <20261117221157.582@kylheku.com>
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
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>

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: Kaz Kylheku <046-301-5902@kylheku.com>
Newsgroups: comp.unix.shell
Subject: Re: Time-stamping files
Date: Wed, 18 Nov 2026 06:19:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 72
Message-ID: <20261117221157.582@kylheku.com>
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>
Injection-Date: Wed, 18 Nov 2026 06:19:05 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1153712"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19V7fNWFc4viu0y3EjbKtO0Wj4a0wAdmU4="; posting-host="a4e765937eb99fc8bc980c57921d9b30"
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:ujzzPYzXkSCbHqYC5nCgAcPFX5Y= sha256:0abILjEtTfpBGyG0Z8cnui/wVXsLxSu5Bd3tMHzaiRc=
	sha1:bVkQ6aTGm6LAgglXmByMb58QhHA= sha256:o2lgxSMelusUrRtS2caneent8m7j4W9mY0bihekls8o=