Article View: comp.unix.shell
Article #386Re: Time-stamping files
From: Janis Papanagnou
Date: Sun, 15 Nov 2026 11:17
Date: Sun, 15 Nov 2026 11:17
65 lines
4108 bytes
4108 bytes
On 2026-11-15 11:11, Brian Patrie wrote: > Janis Papanagnou wrote: > > 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 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). > > The most obvious is, of course: > > for f in * > do > touch $f ; sleep .1 > done > > If heterogeneous number widths are an issue (and there are > no screwy things like control characters in filenames, > and you have GNU ls): > > ls --sort=version | while read f > do > touch $f ; sleep .1 > done Thanks. - A few comments... GNU's "ls --sort=version" answers also point 2) in Kenny's post. (Although not necessary in my case it's good to remember it when necessary.) The "$f" should be quoted, at least to handle any spaces in filenames correctly. (Quoting should also prevent issues with control characters unless newlines spoil the 'while'-loop.) For the typical resources on the internet we should expect spaces in filenames, but quoting should be mandatory anyway. The "obvious" busy-wait with 'sleep' I wanted to avoid. With larger file lists the time may sum up annoyingly. (And why wait if you can just instantly "touch -d ..." with an artificial sub-seconds part. In this case you can write the date in a way that the series of files will get the same base-date with seconds resolution and the individual files only differ in the sub-seconds part that 'ls' will usually not show but implicitly use to sort the files by time if requested. That can of course also be implemented in your 'sleep'-based solution if the constant delay is adjusted to centi- or milliseconds depending on the number of files. Of course only if the used 'sleep' is supporting sub-second resolution. By that we could also guarantee that the summed up delay stays al least within 1 second which would be more acceptable WRT "UX".) Janis
Technical Details
Message-ID:
<11dc4cf$1fnqs$2@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> <11dc0fr$2llji$1@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!.POSTED!not-for-mail From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.unix.shell Subject: Re: Time-stamping files Date: Sun, 15 Nov 2026 12:17:35 +0100 Organization: A noiseless patient Spider Lines: 65 Message-ID: <11dc4cf$1fnqs$2@dont-email.me> References: <11d957u$1fnqs$1@dont-email.me> <11dc0fr$2llji$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sun, 15 Nov 2026 11:17:36 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1564508"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BrF+g0k9m3ZsD/SFdLcBL"; posting-host="6cea999a0e011abbbd147380393d3e19" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:sirAySdYFIKQXvMmzFlQv4RLcGw= sha256:Yn/4V7WiIkE+kyn171pUmLH3mAfMh2eF+XyQZH8+/08= sha1:Pj3Q8Pgn40rKV4gVt9Gvobs8zXI= sha256:8XEaDXLWI3jG0E8nJuSWfzfLpSrmuFWJhjYssmZv34c= In-Reply-To: <11dc0fr$2llji$1@dont-email.me> Content-Language: en-US