GNU bug report logs - #26741
Numeric sort in ls

Previous Next

Package: coreutils;

Reported by: Tony Malykh <anton.malykh <at> gmail.com>

Date: Tue, 2 May 2017 00:59:02 UTC

Severity: normal

Tags: notabug

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Tony Malykh <anton.malykh <at> gmail.com>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: 26741 <at> debbugs.gnu.org
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 <schwab <at> linux-m68k.org> wrote:
> On Mai 01 2017, Tony Malykh <anton.malykh <at> gmail.com> 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, schwab <at> linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."
>




This bug report was last modified 8 years and 23 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.