🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.shell
4 messages
4 total messages Started by Janis Papanagnou Wed, 14 Oct 2026 08:26
Changing collation order with 'ls'
#218
Author: Janis Papanagnou
Date: Wed, 14 Oct 2026 08:26
26 lines
2393 bytes
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'.
Re: Changing collation order with 'ls'
#219
Author: Christian Weisgerber
Date: Wed, 14 Oct 2026 11:42
31 lines
1795 bytes
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
Re: Changing collation order with 'ls'
#220
Author: Janis Papanagnou
Date: Wed, 14 Oct 2026 14:46
35 lines
2938 bytes
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 —
   there's no ~/.locale or environment variable where you could
   put your en_tom setting."
Re: Changing collation order with 'ls'
#228
Author: Christian Weisgerber
Date: Wed, 14 Oct 2026 16:50
10 lines
1195 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads