bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#26741: Numeric sort in ls


From: Tony Malykh
Subject: bug#26741: Numeric sort in ls
Date: Tue, 2 May 2017 17:33:37 -0700

It should be possible from technical point of view to add a new option
--numeric-sort or --natural-sort that wouldn't conflict with -X or any
other sort options of ls.

I am a C++ developer myself, so I can implement this new options
myself. Would the community of coreutils developers be interested in
accepting a patch like this?

I've looked at the source code, and it seems that the function that
does lexicographic sorting is strcoll. The implementation of this
function is quite complicated, and it is implemented in glibc. What I
would propose is to write a new function strcoll_natural in ls code,
that would identify which characters are digits in the input strings.
Then it would pass non-digit chunks to strcoll to preserve the
handling of locales, and it would do the smart comparison of digits as
numbers.

As a separate note, what I dislike about ls -v option is that it
handles capital letters in a different way than without the -v option:
$ ls -1
a
B
c
D

$ ls -1v
B
D
a
c

I have no particular preference among these two, but I'd rather see
them consistent. It seems like this is a known "caveat" of -v option,
since it ignores the locale.

Tony


On 5/2/17, Andreas Schwab <address@hidden> wrote:
> On Mai 01 2017, Tony Malykh <address@hidden> wrote:
>
>> It appears that version sort (-v) option achieves exactly that.
>> However, the problem with it is that it seems to be incompatible with
>> extension sort (-X) option.
>
> This isn't limited to these two option.  Generally, ls only supports a
> single sort option, with later options overriding previous ones.
>
> Andreas.
>
> --
> Andreas Schwab, address@hidden
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."
>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]