• Changing collation order with 'ls'

    From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.unix.shell on Wed Oct 14 10:26:30 2026
    From Newsgroup: comp.unix.shell

    I looked into the mundane appearing question to change the sorting
    order of the 'ls' command. I wanted to have non-'alnum' characters
    come first. The two obvious ways - looking into the (many dozens!)
    of options supported by 'ls', and setting LC_COLLATE (or LC_ALL) -
    strangely, didn't work or show anything appropriate.

    According to the results of a search on the Net there isn't any
    straightforward way to achieve that - and this I think is really
    astonishing! - and the only _functional_ suggestion I found was to
    explicitly enumerate the files with shell patterns like ls _* [!_]*
    (here for the underscore case, which was my concern; handling all
    non-alnum characters would make that pattern even worse). Needless
    to say that patterns don't solve the requirement generally since
    that approach conflicts with regular use of patterns with 'ls'.[*]

    Can that be true, or is there some solution to change the sorting
    order [on the shell command-line level] that I'm missing?

    Janis

    PS: I seem to recall that in former times I've seen filenames shown
    listed with non-alnum characters come first or last, but my memories
    might be wrong here.

    [*] In the sense that I cannot alias once and for all the 'ls'.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Christian Weisgerber@naddy@mips.inka.de to comp.unix.shell on Wed Oct 14 11:42:13 2026
    From Newsgroup: comp.unix.shell

    On 2026-10-14, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    I looked into the mundane appearing question to change the sorting
    order of the 'ls' command. I wanted to have non-'alnum' characters
    come first. The two obvious ways - looking into the (many dozens!)
    of options supported by 'ls', and setting LC_COLLATE (or LC_ALL) -
    strangely, didn't work or show anything appropriate.

    That would depend on the operating system's ls(1) implementation,
    but FreeBSD's does honor LC_COLLATE:

    $ locale
    LANG=C.UTF-8
    LC_CTYPE="C.UTF-8"
    LC_COLLATE="C.UTF-8"
    LC_TIME="C.UTF-8"
    LC_NUMERIC="C.UTF-8"
    LC_MONETARY="C.UTF-8"
    LC_MESSAGES="C.UTF-8"
    LC_ALL=
    $ touch i I -# -#
    $ ls
    I i -# -#
    $ LC_COLLATE=tr_TR.UTF-8 ls
    -# I i -#

    The sysadmin would have to create a locale with your particular
    collation order.
    --
    Christian "naddy" Weisgerber naddy@mips.inka.de
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.unix.shell on Wed Oct 14 16:46:54 2026
    From Newsgroup: comp.unix.shell

    On 2026-10-14 13:42, Christian Weisgerber wrote:
    On 2026-10-14, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    I looked into the mundane appearing question to change the sorting
    order of the 'ls' command. I wanted to have non-'alnum' characters
    come first. The two obvious ways - looking into the (many dozens!)
    of options supported by 'ls', and setting LC_COLLATE (or LC_ALL) -
    strangely, didn't work or show anything appropriate.

    That would depend on the operating system's ls(1) implementation,
    but FreeBSD's does honor LC_COLLATE:
    [...]
    The sysadmin would have to create a locale with your particular
    collation order.

    Thanks. My OS is a Linux. The "sysadmin" (sort of) is in practice
    me, disregarding that some distro system managers define these OS
    things (and regularly replace any changes I do in "their" part of
    the file system with system updates). So defining my own "personal
    locale file" is not exactly what I was looking for.[*]

    I interpret your post that you see no other way, specifically not
    any way to obtain such a function "on the shell command-line level"
    (as I had written in my OP to be seeking)?

    Janis

    [*] See also this old StackExchange comment about that suggestion:
    "To make the underscore appear before uppercase, you would
    need to define your own locale settings. This is possible,
    but awkward to use, because at least under Linux, the standard
    library only looks for locale definitions in /usr/lib/locale rCo
    there's no ~/.locale or environment variable where you could
    put your en_tom setting."

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Christian Weisgerber@naddy@mips.inka.de to comp.unix.shell on Wed Oct 14 16:50:28 2026
    From Newsgroup: comp.unix.shell

    On 2026-10-14, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    I interpret your post that you see no other way, specifically not
    any way to obtain such a function "on the shell command-line level"
    (as I had written in my OP to be seeking)?

    I can't think of anything.
    --
    Christian "naddy" Weisgerber naddy@mips.inka.de
    --- Synchronet 3.22a-Linux NewsLink 1.2