On 2026-11-18, Keith Thompson wrote:
> Nuno Silva <nuno…@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.
I think you didn't miss anything (here it's apparently missing from both
the man and info online manuals), and if a web version of the uutils
manpage is accurate, uutils also doesn't document this properly...
<https://uutils.org/coreutils/docs/utils/ls.html>:
"-t Sort by modification time (the ‘mtime’ in the inode), newest
first."
BSD ls has different wording but mentions it (leaves out the part about
symbolic links, although maybe that's covered by the entry for -L?):
from <https://man.netbsd.org/ls.1>:
"-t Sort by time modified (most recently modified first) before
sorting the operands by lexicographical order."
--
Nuno Silva