Article View: comp.unix.shell
Article #401Re: Time-stamping files
From: Janis Papanagnou
Date: Wed, 18 Nov 2026 07:28
Date: Wed, 18 Nov 2026 07:28
88 lines
3796 bytes
3796 bytes
On 2026-11-17 17:10, Richard Harnden wrote:
> On 14/11/2026 08:13, Janis Papanagnou wrote:
>> [...]
>>
>> 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).
>
> 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.
Thanks.
This - the C-algorithm below - is actually similar to what my shell
script does. The difference is that you're counting micro-seconds
(always as a fixed increment) where I'm adjusting it to the needs
(with the least possible accuracy); I wanted to keep the counter as
close to the seconds as possible.
For comparison, here's the Kornshell script[*] that I'm using...
typeset -i n_files=$#
typeset -i decimals=${#n_files}
typeset -i serial_no=0
typeset -Z${decimals} subseconds
typeset time_now
printf "%(%Y-%m-%d %H:%M:%S)T" | IFS= read time_now
for f in "$@"
do
subseconds=$(( ++serial_no ))
touch -d "${time_now}.${subseconds}" "${f}"
done
An argument list up to 999 files will still stay in the [ms] range,
a handful of file (less than 10) will be represented by time-now.#,
100000 files will require with time-now.###### the range of [µs],
where the '#' symbols represent the sub-seconds decimals.
> [...]
Janis
[*] To rewrite, e.g. for Bash, note...
typeset -i declares an integer variable
typeset -Z{n} declares a numeric variable with n digits (you may
replace that with printf '%0*d' $n $subsec in Bash)
printf "%(...)T" is a built-in time generator/formatter (may be
replaced by the external 'date ...' instead)
... | read var would not work in Bash that way, use $(...) e.g.
>
> #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:
<11djk24$s03n$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news-ams.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> <11dhu8q$ikie$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news-ams.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: Wed, 18 Nov 2026 08:28:04 +0100 Organization: A noiseless patient Spider Lines: 88 Message-ID: <11djk24$s03n$1@dont-email.me> References: <11d957u$1fnqs$1@dont-email.me> <11dhu8q$ikie$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 18 Nov 2026 07:28:05 +0000 (UTC) Injection-Info: dont-email.me; logging-data="917623"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cd6mz2n9+p0EPnWvB90gE"; posting-host="5ee6dba4dd6e97f0b7c430097b954d79" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:MV1wPVN7iA83vIPQd7kgV/JPt58= sha256:fpCULu4vcD76zM8bQ98Bsif6c1D0snX0z8MysG8CrgU= sha1:cteHA76XDVPRjT44iIvKpmr/Jzo= sha256:7oBjnQeeB6JL34v9MmwkSFBaBoGTM6fVTlFnNx9tq38= In-Reply-To: <11dhu8q$ikie$1@dont-email.me> Content-Language: en-US