ls sort problem

Hello.

tux_user@ASUS-JC-NEW:~> ls -al --group-directories-first
total 224                                                                                                             
drwxr-xr-x 21 tux_user users   4096 14 nov.  11:10 .                                                                  
drwxr-xr-x  6 root     root      66 13 nov.  13:14 ..                                                                 
**drwxr-xr-x  2 tux_user users      6 11 nov.  15:44 bin**                                                                
drwxr-xr-x  8 tux_user users   4096 14 nov.  11:10 .cache                                                             
drwx------ 13 tux_user users   4096 14 nov.  11:10 .config                                                            
drwx------  3 tux_user users     25 11 nov.  15:45 .dbus                                                              
**drwxr-xr-x  2 tux_user users     65 11 nov.  15:46 Desktop**                                                            
**drwxr-xr-x  2 tux_user users      6 11 nov.  15:45 Documents                                                          
drwxr-xr-x  4 tux_user users    149 12 nov.  14:36 Downloads                                                          
**drwxr-xr-x  2 tux_user users     23 11 nov.  15:45 .fonts                                                             
drwxr-xr-x  3 tux_user users    179 12 nov.  12:36 .kde4                                                              
drwx------  3 tux_user users     19 11 nov.  15:45 .local                                                             
drwx------  4 tux_user users     39 11 nov.  17:12 .mozilla                                                           
**drwxr-xr-x  2 tux_user users      6 11 nov.  15:45 Music                                                              
drwxr-xr-x  2 tux_user users      6 11 nov.  15:45 Pictures                                                           
drwxr-xr-x  2 tux_user users      6 11 nov.  15:45 Public
drwxr-xr-x  2 tux_user users     24 11 nov.  15:44 public_html
**drwxr-xr-x  3 tux_user users     59 24 oct.   2015 .putty
drwxr-xr-x  2 tux_user users    136 13 nov.  13:22 .ssh
**drwxr-xr-x  2 tux_user users      6 11 nov.  15:45 Templates
drwxr-xr-x  2 tux_user users      6 11 nov.  15:45 Videos
**-rw-------  1 tux_user users    295 12 nov.  16:08 .bash_history
-rw-r--r--  1 tux_user users   1177 11 nov.  15:44 .bashrc
-rw-r--r--  1 tux_user users   1637 11 nov.  15:44 .emacs
-rw-------  1 tux_user users     16 11 nov.  15:46 .esd_auth
**-rw-r--r--  1 tux_user users     37 11 nov.  17:13 firefox_initial_config.txt
**-rw-r--r--  1 tux_user users    367 11 nov.  15:45 .gtkrc-2.0
-rw-r--r--  1 tux_user users    305 11 nov.  15:44 .i18n
-rw-r--r--  1 tux_user users    861 11 nov.  15:44 .inputrc
-rw-r--r--  1 tux_user users   1028 11 nov.  15:44 .profile
-rw-------  1 tux_user users    333 12 nov.  19:26 .recently-used
-rw-------  1 tux_user users     56 14 nov.  11:10 .Xauthority
-rw-r--r--  1 tux_user users   1952 11 nov.  15:44 .xim.template
-rwxr-xr-x  1 tux_user users   1112 11 nov.  15:44 .xinitrc.template
-rw-r--r--  1 tux_user users   8227 12 nov.  15:14 .xscreensaver
-rw-r--r--  1 tux_user users   8226 12 nov.  13:12 .xscreensaver~
-rw-------  1 tux_user users      0 14 nov.  11:10 .xsession-errors
-rw-------  1 tux_user users  13403 14 nov.  11:11 .xsession-errors-:0
-rw-r--r--  1 tux_user users 114487 11 nov.  20:41 .y2log
-rw-r--r--  1 tux_user users    282 11 nov.  20:41 .y2usersettings
tux_user@ASUS-JC-NEW:~> 

Hidden directories does not appear first
Hidden files does not appear first
There is no problem on OS 13.2

There is no problem with dolphin ( sorting mode = alphabetical sorting, case sensitive )
There is no problem on OS 13.2 ( natural sorting of items = unticked )

Any comments are welcome

And why do you call it a problem?
You told ls to show directories first (and it does), not that it should show hidden files/directories first… :wink:

It seems to apply some sort of natural sorting (e.g. .cache is treated equally to cache).
If that didn’t happen in 13.2 it may be a change in ls, or it may be related to the locale.

Btw, I just checked, and it does exactly behave like that here on 13.2:


wolfi@amiga:~> lsb-release -r
Release:        13.2
wolfi@amiga:~> ls -a
.
..
abgabe.dsk
.AbiSuite
.abuse
.acetoneiso
ActionReplay3Handbuch.zip
.addressbook
.adobe
AGReader
...

So ls doesn’t seem to have changed in this regard…

There is no problem with dolphin ( sorting mode = alphabetical sorting, case sensitive )
There is no problem on OS 13.2 ( natural sorting of items = unticked )

dolphin’s behavior is completely unrelated to ls.
And with “alphabetic sorting” (“natural sorting” turned off), .cache is indeed different than cache, and ‘.’ comes before any alphabetical character (A-Z/a-z).
The point of “natural sorting” is to ignore this technical difference though.

PS: using e.g. the “C” locale should “fix” your “problem”…

wolfi@amiga:~> LANG=C ls -al --group-directories-first
total 150899
drwxr-xr-x 219 wolfi users     10992 Nov 14 11:01 .
drwxr-xr-x   5 root  root        128 Oct 19 21:15 ..
drwxr-xr-x   2 wolfi users       120 Feb 22  2013 .AbiSuite
drwx------   3 wolfi users        96 Feb 28  2011 .FontForge
drwx------   2 wolfi users        48 Oct 25 23:06 .QtWebEngineProcess
drwx------   3 wolfi users       136 Sep 12  2007 .Skype
drwxr-xr-x   2 wolfi users       696 Nov 14 09:15 .VirtualBox
drwxr-xr-x   4 wolfi users       904 Nov 19  2013 .aMule
drwxr-xr-x   2 wolfi users       288 Jun 24  2013 .abuse
drwxr-xr-x   2 wolfi users       240 Dec  4  2015 .acetoneiso
...
drwxr-xr-x   4 wolfi users       184 Dec  5  2001 AGReader
drwxr-xr-x   3 wolfi users       120 Nov  2  2010 Commodore Amiga - {Games,Educational,Coverdisk} - SPS
drwx------  56 wolfi users      5848 Nov 14 11:43 Desktop
drwxr-xr-x   8 wolfi users      1944 Sep  6 21:57 Documents
...

Though actually this is controlled by “LC_COLLATE”, you’d only need to change that.
E.g.:

LC_COLLATE=C ls -al --group-directories-first

Or change your locale settings accordingly.

Thank you for your quick answer.
I would like to have alphabetical sorting with case insensitive for every user.

total 180
drwxr-xr-x  2 tux_user users     6 Nov 16 09:32 #1
drwxr-xr-x 30 tux_user users  4096 Nov 16 11:53 .
drwxr-xr-x  6 root     root    122 Nov 14 22:45 ..
drwxr-xr-x  8 tux_user users  4096 Nov 16 11:50 .cache
drwx------ 12 tux_user users  4096 Nov 16 11:50 .config
drwx------  3 tux_user users    25 Nov 14 17:50 .dbus
drwxr-xr-x  2 tux_user users    23 Nov 14 17:50 .fonts
drwxr-xr-x 24 tux_user users  4096 Nov 16 11:28 .gimp-2.8
drwxr-xr-x  3 tux_user users   179 Nov 16 11:29 .kde4
drwx------  3 tux_user users    19 Nov 14 17:50 .local
drwx------  4 tux_user users    39 Nov 14 18:24 .mozilla
drwx------  3 tux_user users    20 Nov 16 11:06 .thumbnails
drwxr-xr-x  2 tux_user users     6 Nov 16 09:31 00
drwxr-xr-x  2 tux_user users     6 Nov 16 09:31 030
drwxr-xr-x  2 tux_user users     6 Nov 16 10:22 1
drwxr-xr-x  2 tux_user users    65 Nov 14 17:50 Desktop
drwxr-xr-x  2 tux_user users    26 Nov 16 11:28 Documents
drwxr-xr-x  2 tux_user users     6 Nov 14 17:50 Downloads
drwxr-xr-x  2 tux_user users     6 Nov 14 17:50 Music
drwxr-xr-x  2 tux_user users    56 Nov 16 11:05 Pictures
drwxr-xr-x  2 tux_user users     6 Nov 14 17:50 Public
drwxr-xr-x  2 tux_user users     6 Nov 14 17:50 Templates
drwxr-xr-x  2 tux_user users     6 Nov 14 17:50 Videos
drwxr-xr-x  2 tux_user users     6 Nov 16 10:23 X
drwxr-xr-x  2 tux_user users     6 Nov 16 10:22 _00
drwxr-xr-x  2 tux_user users     6 Nov 16 10:22 _030
drwxr-xr-x  2 tux_user users     6 Nov 16 10:24 a
drwxr-xr-x  2 tux_user users     6 Nov 14 17:49 bin
drwxr-xr-x  2 tux_user users    24 Nov 14 17:49 public_html
drwxr-xr-x  2 tux_user users     6 Nov 16 10:23 x
-rw-r--r--  1 tux_user users     0 Nov 16 10:27 #0.txt
-rw-r--r--  1 tux_user users     0 Nov 16 10:28 #00.txt
-rw-------  1 tux_user users    56 Nov 16 10:56 .Xauthority
-rw-------  1 tux_user users   261 Nov 16 11:05 .bash_history
-rw-r--r--  1 tux_user users  1177 Nov 14 17:49 .bashrc
-rw-------  1 tux_user users   283 Nov 14 18:40 .directory
-rw-r--r--  1 tux_user users  1637 Nov 14 17:49 .emacs
-rw-------  1 tux_user users    16 Nov 14 17:50 .esd_auth
-rw-r--r--  1 tux_user users   367 Nov 14 17:50 .gtkrc-2.0
-rw-r--r--  1 tux_user users   305 Nov 14 17:49 .i18n
-rw-r--r--  1 tux_user users   861 Nov 14 17:49 .inputrc
-rw-r--r--  1 tux_user users  1028 Nov 14 17:49 .profile
-rw-r--r--  1 tux_user users  1952 Nov 14 17:49 .xim.template
-rwxr-xr-x  1 tux_user users  1112 Nov 14 17:49 .xinitrc.template
-rw-------  1 tux_user users     0 Nov 16 10:56 .xsession-errors
-rw-------  1 tux_user users 83232 Nov 16 11:53 .xsession-errors-:0
-rw-------  1 tux_user users 22864 Nov 15 09:14 .xsession-errors-:1
-rw-r--r--  1 tux_user users     0 Nov 16 10:27 0.txt
-rw-r--r--  1 tux_user users     0 Nov 16 10:28 00.txt
-rw-r--r--  1 tux_user users     0 Nov 16 10:28 030.txt
-rw-r--r--  1 tux_user users     0 Nov 16 10:28 1.txt
-rw-r--r--  1 tux_user users     0 Nov 16 10:22 A.txt
-rw-r--r--  1 tux_user users     0 Nov 16 10:28 X.txt
-rw-r--r--  1 tux_user users     0 Nov 16 10:25 a.txt
-rw-r--r--  1 tux_user users    10 Nov 15 09:11 konsole.txt
-rw-r--r--  1 tux_user users     0 Nov 16 11:54 test.txt
-rw-r--r--  1 tux_user users     0 Nov 16 11:53 x.txt
.
.

It is not case insensitive

tux_user@MY-SERVER-LINUX:~> env | grep LC_
LC_CTYPE=en_US.UTF-8
tux_user@MY-SERVER-LINUX:~>

 
tux_user@MY-SERVER-LINUX:~> locale
LANG=POSIX
LC_CTYPE=en_US.UTF-8
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"                              
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
tux_user@MY-SERVER-LINUX:~> 


What to change or set and where?

Any help is welcome

Yes, that’s how the “C” (POSIX) locale is defined. It strictly sorts by the ASCII code. So ‘B’ comes after ‘A’, but before ‘a’.

What to change or set and where?

You can change the system locale in /etc/sysconfig/language or /etc/locale.conf.
Your desktop should provide a possibility to change it for the user.
In KDE/Plasma5 that’s “Configure Desktop”->“Regional Settings”->“Formats”.

Again, you only need to change LC_COLLATE (“Collation and Sorting” in KDE’s settings) for this.

I cannot tell you which locale will behave as you want it though, you’ll have to find out yourself.

I would like ls work as dolphin work with the sorting mode = alphabetical sorting, case sensitive (** leap 42.2 **)

Hm? I think you mean case in-sensitive here. Your previous output was case sensitive… :wink:

As I wrote, I cannot tell you which locale would do that.
You need to try and find one yourself, or create one but I have no idea how to do that either.

I see no options in ls regarding this.

Another possibility would probably be to pipe ls’s output through sort though, see “man sort”.
But you’d need to change ls’s output format then.

PS: actually it should even work with the standard ls output if you use the --key option appropriately.
Although the problem with sort is that you won’t be able to keep the directories separate… :\