0

Ex. suppose some directories are named

absorbing
appreciate
arrive
connect
depend
drop
few
fold
littlel
popcorn
shrill
sticky

In Windows, if I put _ before the directories, it would be at the top, like this.

_connect
_few
_little
_shrill
absorbing
appreciate
arrive
depend
drop
fold
popcorn
sticky

However, the same directories look the following when sorted alphabetically in Nemo 4.0.6 (to be specific, Linux Mint 19.1, Cinnamon 4.0.10)

absorbing
appreciate
arrive
_connect
depend
drop
_few
fold
_little
popcorn
_shrill
sticky

So, the sort algorithm, in Nemo is completely ignoring _ at the beginning of directory name.

I want the sorting to work like in the first listing, is there any way to do that?

  • 1
    What tool are you using (ls, a file-manager, …)? – ctrl-alt-delor Apr 4 at 15:33
  • 2
    This is about sorting in Nemo, right? – terdon Apr 4 at 15:49
  • (no time to write this up, leaving as pointer for someone) — ls will do this too, it's the default sorting in at least en_US.UTF-8. LC_COLLATE=C will not. – derobert Apr 4 at 15:54
  • 1
  • 1
    That's consistent with the ISO14651 standard (see line <U005F> IGNORE;IGNORE;IGNORE;<U005F> % LOW LINE meaning _ is to be ignored for sorting). – Stéphane Chazelas Apr 4 at 16:15
0

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.

  1. go to /usr/share/i18n/locales/

  2. make a copy of your desired locale definition (i.e. en_US to en_US_sorted)

  3. make copies of the files that contain the ordering information (iso14651_t1 and iso14651_t1_common)

  4. edit en_US_sorted to use iso14651_t1_sorted instead of iso14651_t1

  5. edit iso14651_t1_sorted to use iso14651_t1_common_sorted instead of iso14651_t1_common

  6. make the desired changed to iso14651_t1_common_sorted

To make underscores appear first, I changed the line

<U005F> IGNORE;IGNORE;IGNORE;<U005F> # 33 _

to

<U005F> <RES-1>;IGNORE;IGNORE;<U005F> # 33 _
  1. Put en_US_sorted.UTF-8 UTF-8 in /etc/locale.gen & Run sudo 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.

  1. Run validlocale en_US_sorted.UTF-8 to validate the new locale file.

  2. tell the system to use the new locale (sudo localectl set-locale LANG=en_US_sorted.utf8)

  3. reboot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.