3


I'm trying to make Linux include special characters when sorting filenames. The sort order I'm trying to achieve is: first all special characters, then numbers, then letters (case insensitive).

The default sort in Linux completely ignores special characters (see the first column "ls-before" in the examples).

One suggestion I found was to use LC-COLLATE=C or LC_ALL=C. This indeed considers special characters, but they are sorted in strange ways: some are sorted before numbers, some between numbers and capital letters, and underscore is placed between capital and small letters. And all capital letters come before all small letters. Also not what I want (second column in examples).

I've tried editing /usr/share/i18n/locales/iso14651_t1_common: changed the lines with special characters from IGNORE;IGNORE;IGNORE to <RES-1>;IGNORE;IGNORE

eg <U005F> IGNORE;IGNORE;IGNORE;<U005F> # 33 _
to <U005F> <RES-1>;IGNORE;IGNORE;<U005F> # 33 _

Then I recompiled the locale (en_GB) with sudo localedef -i en_GB -f UTF-8 -vc en_GB (I didn't change the locale itself)

Sorting files now does include special characters and they all appear before the numbers (which is what I want), but the special characters seem to be used merely for grouping, not for sorting (see column "ls-after" in the examples). Sorting seems to be based on the character following the special character. Sorting on the special character should produce a result more akin to the column "desired".

Examples:


    ls-before     LC_COLLATE=C   caja        nemo      ls-after  desired
    -----------   ------------   -----       -----     --------  -------
    1             %b             1           1         =a        =a
    11            1              2           2         _a        =b
    111           11             3           3         =b        _a
    2             111            11          11        _b        _b
    3             2              111         111       %b        %b
    a             3              =a          a         1         ..
    =a            =a             _a          =a        11        ..
    _a            =b             =b          _a        111       .. 
    A             A              _b          A         2         ..
    aa            AA             %b          aa        3         ..
    AA            AB             a           AA        a         ..
    ab            Ab             A           ab        A         .. 
    a_b           B              a_b         a_b       a_b       a_b
    a-b           BB             a-b         a-b       a-b       a_c 
    a#b           _a             a#b         a#b       a#b       a_C
    a%b           _b             a%b         a%b       a%b       a-b
    aB            a              a_c         aB        a_c       a-c 
    Ab            a#b            a-c         Ab        a-c       a#c
    AB            a%b            a_C         AB        a_C       a&c
    ac            a-b            aa          ac        aa        ..
    a_c           a-c            AA          a_c       AA        ..
    a-c           aB             ab          a-c       ab        ..
    a_C           a_C            aB          a_C       aB        ..
    b             a_b            Ab          b         Ab        ..
    =b            a_c            AB          =b        AB        ..
    _b            aa             ac          _b        ac        ..
    %b            ab             b           %b        b         ..
    B             ac             B           B         B         ..
    bb            b              bb          bb        bb        ..
    BB            bb             BB          BB        BB        ..

Does anyone have an idea on how to truly sort the special characters instead of just grouping them?

On a sidenote, I would have liked all applications to follow the new sorting, but it looks like every application has its own rules for sorting files (see columns "caja" and "nemo"). Is there a way to force every application to follow the same sorting, or is sorting hard coded in the applications? My alternations in iso14651_t1_common had no effect on the sorting in Nemo, but made Caja behave like Nemo.

Using Linux mint 18.3 mate. Not sure if this is important, but I'm using a dual boot system with my data on an NTFS drive, so any solution should work on NTFS as well.

Thanks!

Your Answer

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

Browse other questions tagged or ask your own question.