🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #393

Re: Time-stamping files

#393
From: Richard Harnden
Date: Tue, 17 Nov 2026 16:10
60 lines
3091 bytes
On 14/11/2026 08:13, 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).
> 
> Janis
> 

It's not shell, but maybe this does what you want ...

Starts with 'now' and zero usec, and adds 1 usec per file.
Assuming you don't really care what the timestamps are, only that they 
increase.

(I tried with 'echo * | xargs -l touch' too, but that doesn't work)

#include <time.h>
#include <sys/time.h>

int main(int argc, char *argv[])
{
     struct timeval times[2];

     times[0].tv_sec = time(NULL);
     times[1].tv_sec = times[0].tv_sec;

     times[0].tv_usec = 0;
     times[1].tv_usec = 0;

     for (int i=1; i<argc; i++)
     {
         if ( utimes(argv[i], times) != 0 )
             return 1;

         times[0].tv_usec += 1;
         times[1].tv_usec += 1;
     }

     return 0;
}




Technical Details
Message-ID: <11dhu8q$ikie$1@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-mail
References: <11d957u$1fnqs$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: Richard Harnden <richard.nospam@gmail.invalid>
Newsgroups: comp.unix.shell
Subject: Re: Time-stamping files
Date: Tue, 17 Nov 2026 16:10:01 +0000
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <11dhu8q$ikie$1@dont-email.me>
References: <11d957u$1fnqs$1@dont-email.me>
Reply-To: nospam.harnden@invalid.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 17 Nov 2026 16:10:03 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="610894"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19IJzGCCw3TQxq0ul6qdJ+lLb6E5MqD00A="; posting-host="5cd12e789272658b22aeb5d4cd2fab73"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:tOy8weNC7OuARykewM7OIAn+L+o= sha256:F51HV7Z/w8p0c/1N2OxhPJpTP+Xm4b9FswH9RPH//Ac=
	sha1:PbW45XDinIfmkIamDFn3GqXjwTQ= sha256:9nP6KrsuiGUQ38RD1GBj8G57y83y3O+rGm9B+d6Satw=
Content-Language: en-GB
In-Reply-To: <11d957u$1fnqs$1@dont-email.me>