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).
But I have 3 general comments/concerns:
1) If you touch them on-masse, isn't there some risk that they all end
up with the same timestamp - even if "touch" does re-calculate the
current time for each file - on a sufficiently fast machine? What is
the granularity of file timestamps on your system?
2) If you use the shell to expand the list, won't you fall into the old
"10 sorts before 2" problem?
3) I'm surprised that the files aren't already time-stamped in the same
order in which they were downloaded. Wouldn't that already be what you
want?
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.
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 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
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.
Janis Papanagnou wrote:
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.
Which version of touch?
POSIX requires that touch processes the files in the order they are
given. (XCU 1.4 Utility Description Defaults, under "OPERANDS":
"Unless otherwise stated, the standard utilities that accept operands
shall process those operands in the order specified in the command
line." The OPERANDS section for touch does not state otherwise.)
Running GNU touch from coreutils 9.1 under strace on Linux shows it
processes the files in the correct order...
[...]
If your version of touch really is processing them in reverse, you
should report it as a bug.
$ touch --version
touch (GNU coreutils) 9.4
...
$ touch 6 7 8 9
and the 'stat' command for these four files shows
2026-11-16 16:13:47.212143070 +0100 7
2026-11-16 16:13:47.212143070 +0100 8
2026-11-16 16:13:47.212143070 +0100 9
2026-11-16 16:13:47.211143078 +0100 6 <<< ...78 ns
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 Papanagnou wrote:
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.
Which version of touch?
POSIX requires that touch processes the files in the order they are
given.
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).
There's nothing wrong with writing a script do that, but I probably
wouldn't bother.
My system (with an ext4 filesystem) stores timestamps with nanosecond precision (but not, apparently, nanosecond accuracy). Others
might not. IIRC, FAT32 has 2-second precision.
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
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).
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 think you were observing the output of `ls -tr` and *incorrectly*
assuming that it indicated that, for example, 0 is newer than 1,
when in fact 0 and 1 have the same timestamp, but `ls -tr` uses
some other criterion to decide how to sort them.
Reading the GNU coreutils ls documentation, I don't see any mention
of how `ls -tr a b` orders its output when a and b have the same
timestamp. I speculate that if the timestamps are the same, it
falls back to locale-specific alphabetical sorting -- and since
the `-r` (`--reverse`) option was given, it sorts b before a.
Someone could examine the source code.
Note that newer Ubuntu releases use uutils, the Rust reimplementation
of coreutils. It's *supposed* to work the same way. You might
consider other implementations as well (*BSD, busybox, toybox)
depending on how much you care about portability.
`touch a b c` appears to guarantee that the timestamps satisfy
a <= b <= c. If you require a < b < c, you'll need to do a little
more work.
GNU coreutils touch lets you specify the timestamp you want. A script
that touches each of a list of files with a unique timestamp could start
with the current time, and increment it by one nanosecond for each file.
This assumes the filesystem supports nanosecond-resolution timestamps
(not all do).
POSIX specifies the `-d` option to touch and allows fractional seconds,
but it doesn't specify how many digits are significant.
[...]
On 2026-11-17, Keith Thompson wrote:[...]
[...]Reading the GNU coreutils ls documentation, I don't see any mention
of how `ls -tr a b` orders its output when a and b have the same
timestamp. I speculate that if the timestamps are the same, it
falls back to locale-specific alphabetical sorting -- and since
the `-r` (`--reverse`) option was given, it sorts b before a.
Someone could examine the source code.
If it doesn't fall back to that, it should, at least if I'm reading
right. IEEE 1003.1-2008 says it should sort by "filename in the
collating sequence":
®?t Sort with the primary key being time modified (most recently
modified first) and the secondary key being filename in the
collating sequence. [...]¯
2024 at opengroup.org has the same: <https://pubs.opengroup.org/onlinepubs/9799919799/utilities/ls.html>
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.
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.
[...]Janis
#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;
}
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 think you were observing the output of `ls -tr` and *incorrectly*
assuming that it indicated that, for example, 0 is newer than 1,
when in fact 0 and 1 have the same timestamp, but `ls -tr` uses
some other criterion to decide how to sort them.
Reading the GNU coreutils ls documentation, I don't see any mention
of how `ls -tr a b` orders its output when a and b have the same
timestamp. I speculate that if the timestamps are the same, it
falls back to locale-specific alphabetical sorting -- and since
the `-r` (`--reverse`) option was given, it sorts b before a.
Someone could examine the source code.
Note that newer Ubuntu releases use uutils, the Rust reimplementation
of coreutils. It's *supposed* to work the same way. You might
consider other implementations as well (*BSD, busybox, toybox)
depending on how much you care about portability.
`touch a b c` appears to guarantee that the timestamps satisfy
a <= b <= c. If you require a < b < c, you'll need to do a little
more work.
GNU coreutils touch lets you specify the timestamp you want. A script
that touches each of a list of files with a unique timestamp could start
with the current time, and increment it by one nanosecond for each file.
This assumes the filesystem supports nanosecond-resolution timestamps
(not all do).
POSIX specifies the `-d` option to touch and allows fractional seconds,
but it doesn't specify how many digits are significant.
On 2026-11-17, Keith Thompson wrote:
[...]
Reading the GNU coreutils ls documentation, I don't see any mention
of how `ls -tr a b` orders its output when a and b have the same
timestamp. I speculate that if the timestamps are the same, it
falls back to locale-specific alphabetical sorting -- and since
the `-r` (`--reverse`) option was given, it sorts b before a.
Someone could examine the source code.
If it doesn't fall back to that, it should, at least if I'm reading
right. IEEE 1003.1-2008 says it should sort by "filename in the
collating sequence":
®?t Sort with the primary key being time modified (most recently
modified first) and the secondary key being filename in the
collating sequence. [...]¯
2024 at opengroup.org has the same: <https://pubs.opengroup.org/onlinepubs/9799919799/utilities/ls.html>
[...]
[...]
The point is that with spurious 'sleep' delays you could get strange
results; e.g. in the meantime downloaded files could get in-between.
So the dates should be close together, and since I can do my counts
in the sub-seconds parts the *nice* _side-effect_ is that the set of
files will carry the same timestamp.
[...]
Nuno Silva <nunojsilva@invalid.invalid> writes:
On 2026-11-17, Keith Thompson wrote:[...]
[...]Reading the GNU coreutils ls documentation, I don't see any mention
of how `ls -tr a b` orders its output when a and b have the same
timestamp. I speculate that if the timestamps are the same, it
falls back to locale-specific alphabetical sorting -- and since
the `-r` (`--reverse`) option was given, it sorts b before a.
Someone could examine the source code.
If it doesn't fall back to that, it should, at least if I'm reading
right. IEEE 1003.1-2008 says it should sort by "filename in the
collating sequence":
®?t Sort with the primary key being time modified (most recently
modified first) and the secondary key being filename in the
collating sequence. [...]¯
2024 at opengroup.org has the same:
<https://pubs.opengroup.org/onlinepubs/9799919799/utilities/ls.html>
You're right. POSIX does specifies that `ls -tr` uses the filename
in the collating sequence as the secondary key. The GNU coreutils documentation doesn't specify that (unless I missed something),
but it does behave that way.
On 2026-11-17 22:40, Keith Thompson wrote:[...]
I don't think you had said that you wanted unique timestamps.
I wanted _ascending_ timestamps.
The point is that with spurious 'sleep' delays you could get strange
results; e.g. in the meantime downloaded files could get in-between.
So the dates should be close together, and since I can do my counts
in the sub-seconds parts the *nice* _side-effect_ is that the set of
files will carry the same timestamp.
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.
Yes, they can be the same or different (as said before; and see my
previously posted 'stat' output example).
I think you were observing the output of `ls -tr` and *incorrectly*
assuming that it indicated that, for example, 0 is newer than 1,
when in fact 0 and 1 have the same timestamp, but `ls -tr` uses
some other criterion to decide how to sort them.
Yes and no. As seen in my previously posted data the files with the
same internal timestamp are ordered, of course not by the timestamp
but by something else; may it be the name, or the physical position
in the directory, or whatever; that order is *also* affected by the
'-r'. So me have some mixture, primary search criterion is the time,
and the secondary criterion isn't clear to me.
Reading the GNU coreutils ls documentation, I don't see any mention
of how `ls -tr a b` orders its output when a and b have the same
timestamp. I speculate that if the timestamps are the same, it
falls back to locale-specific alphabetical sorting -- and since
the `-r` (`--reverse`) option was given, it sorts b before a.
Someone could examine the source code.
Yes, that's one possibility. (It's just not transparent which one
it actually is.)
POSIX specifies the `-d` option to touch and allows fractional
seconds, but it doesn't specify how many digits are significant.
Yes, that's what I've been using in my script. - I suppose that the
supported resolution may depend on the filesystem.
The "$f" should be quoted
| Sysop: | Jacob Catayoc |
|---|---|
| Location: | Pasay City, Metro Manila, Philippines |
| Users: | 5 |
| Nodes: | 4 (0 / 4) |
| Uptime: | 498677:42:41 |
| Calls: | 212 |
| Calls today: | 3 |
| Files: | 912 |
| D/L today: |
31 files (22,593K bytes) |
| Messages: | 69,841 |