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; > } > > > > >