In case of TL;DR:, You can start from NOTE:
I got the solution from [Feature Request] Pure ASCII filename sorting
Which referred to -
How can I make “ls” show dotfiles first while staying case-insensitive?
And I think he forgot to refer to -
Specify the sort order with LC_COLLATE so lowercase is before uppercase
I am now copy pasting the solution here with a little modification to make it simpler & in case it gets deleted from github.
Summary: in order to get the desired sorting, you need to create your own localization. The actual sorting information is in the file
iso14651_t1_common, which is referred to by
iso14651_t1, which is in turn used by the actual locale definition (i.e. en_US, or whatever you prefer to use). We will make copies of all the files we change, compile those copies and tell the system to use the resulting binary.
NOTE: start from step 1. However, If you do not like the hassle, There is a solution just for
en_US_sorted.UTF-8. download the zip file from tinyupload or google drive. Copy paste the locale files within the zip file in
/usr/share/i18n/locales/ and jump to step 7.
make a copy of your desired locale definition (i.e.
make copies of the files that contain the ordering information (
en_US_sorted to use
iso14651_t1_sorted instead of
iso14651_t1_sorted to use
iso14651_t1_common_sorted instead of
make the desired changed to
To make underscores appear first, I changed the line
<U005F> IGNORE;IGNORE;IGNORE;<U005F> # 33 _
<U005F> <RES-1>;IGNORE;IGNORE;<U005F> # 33 _
en_US_sorted.UTF-8 UTF-8 in
/etc/locale.gen & Run
sudo locale-gen. You do not need to compile your locale definition using
localedef -i en_US_sorted -f UTF-8 -vc en_US_sorted.UTF-8 because -
locale-gen is a program that reads the file /etc/locale.gen and
invokes localedef for the chosen localisation profiles.
validlocale en_US_sorted.UTF-8 to validate the new locale file.
tell the system to use the new locale (
sudo localectl set-locale LANG=en_US_sorted.utf8)