Subject: bug#27127: Failure in "ls -t" when parameter list is long

From: Pádraig Brady <[email-masked]>
Date: Mon, 29 May 2017 01:46:04 +0100

On 28/05/17 18:21, Teppo Mäenpää wrote:
> Dear all,
> 
> The command "ls -t" fails to sort files as promised, when the total length of 
> the names of the files to be listed (and sorted) exceeds 128 KB. All files 
> are still listed, just the sorting part stops working.
> 
> Man page does not mention that the sorting would work only with short file 
> lists. Is this a bug? If not, what have I understood wrong?
> 
> The attached script demonstrates this, in three slightly different scenarios. 
> The outcome of the script is that the total lenght of filenames, given to ls 
> as command line parameter, appears significant.

128K is the defafult max arg size for xargs,
so I presume you're using xargs with ls and
thus you're getting separate invocations of ls.
When commands need to operate on all files at once
(like wc and du to print totals for example)
they have the --files0-from option to take input
on stdin from xargs rather than through command arguments.
Now this option might be added to ls, though while
sorting is an operation that needs to operate on all data,
it has scalability issues best dealt with in the external sort command
(handling tmp files etc. for arbitrarily large inputs).

For example I've done this sort of ordering in the past
with the `find | sort | xargs ls` pattern, which you can see in:
http://www.pixelbeat.org/scripts/newest

cheers,
Pádraig