Sorting by name doesn't work well with digits or special chars

Bug #322271 reported by Stefan Kranich
64
This bug affects 11 people
Affects Status Importance Assigned to Milestone
Nautilus
Confirmed
Medium
nautilus (Ubuntu)
Triaged
Low
Unassigned

Bug Description

Binary package hint: nautilus

On my local disk there is a folder with the following contents:

stefan@ubuntu:~/Dokumente/*/*/*/FLASCHEN_15cm$ ls
0,2LMW 0,33LMW 0,5LMW 0,5LMWPET 1,0LEWPET 1,5LEWPET

I did not include the full path for legal reasons, since it includes names of my customers and brand names. Instead of these, I put * to indicate another subdirectory.

However, when I display this folder in nautilus sorting alphabetically by file name, the resulting order is:

0,2LMW 0,5LMW 0,5LMWPET 0,33LMW 1,0LEWPET 1,5LEWPET

ProblemType: Bug
Architecture: i386
DistroRelease: Ubuntu 8.10
ExecutablePath: /usr/bin/nautilus
NonfreeKernelModules: ath_hal
Package: nautilus 1:2.24.1-0ubuntu1
ProcEnviron:
 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
 LANG=de_DE.UTF-8
 SHELL=/bin/bash
SourcePackage: nautilus
Uname: Linux 2.6.27-9-generic i686

Tags: apport-bug
Revision history for this message
Stefan Kranich (philomath) wrote :
Revision history for this message
Pedro Villavicencio (pedro) wrote :

Thanks for the report, that looks like bug http://bugzilla.gnome.org/show_bug.cgi?id=355152 ; which is known upstream, linking the report, thanks.

Changed in nautilus:
assignee: nobody → desktop-bugs
importance: Undecided → Low
status: New → Triaged
Changed in nautilus:
status: Unknown → New
Revision history for this message
Marcello Romani (marcello-romani) wrote :

Hi, The gnome bugzilla report is exactly what I'm seeing too.

Linux 2.6.31-21-generic #59-Ubuntu SMP Wed Mar 24 07:28:56 UTC 2010 i686 GNU/Linux

/etc/debian_version squeeze/sid

Ubuntu 9.10 fully updated as of 2010-04-27

The gnome bugzilla report is from 2006 and still "unconfirmed". Is there something that we (i.e. normal users) can do to speed things up ?

Changed in nautilus:
status: New → Confirmed
Revision history for this message
Grizzly (sven-witterstein) wrote :

Just my 2 cents (same as in gnome-bugzilla 355152)

Cheap, general solution:
- Make an option available in Gconf to change between "ascii" "natural" (=the
current with respect to numbers that are NOT prefixed with "0" ) and
"dos/win-Style" ( prefixes with . in front of the rest, folders separated")

Better solution:
- offer a per-directory config option in addition.
Reason: on my "linux" files, I can live perfectly happy with "natural" sort
order though it "feels" sometimes "weird" and "buggy" - but I do have to mount
a lot of stuff created under windumb - so "win-style" Order should be default
for ntfs-partitions and be selectable for all those dirs from my co-workers
that have all the "!" "__" "_" etc. prefixing to put important stuff, such as
"_main.cpp" on top of a source dir.

It would be so nice to find a solution that offers - thoug hidden in gconf -
choice over the flame war going on here..

Revision history for this message
Grizzly (sven-witterstein) wrote :

I personally think the reason is "natural sort order" does:
a) not interpret the german "," decimal separator as such
b) not even aussume fractal base 10 - Numbers to be in a filename
c) therefore, it interprets the number as integer, starting after the "," - so it sees
   something mor like 2-dim vector in this filename, putting the <1l bottles before the >=1l bottles,
  and then intepreting the numbers after the "," as "second index", thus sorting
  2 - 5 - 33
  0,2LMW 0,33LMW 0,5LMW 0,5LMWPET 1,0LEWPET 1,5LEWPET

I think this is a good example why "naturally" sorting will never work perfectly, because no tool will ever know if you try to provide tuples or german-style fractals in this filename (even if you mess with the locale - how shall nautilus know if the filename has the same locale "in mind" than itself (the given filenames could be created by a german who sends them to an english speaker with a "."-aware locale on his system. On windows, I would name the files
0,20l-mw 0,33l-mw, 0,50l-mw 0,50l-mw 1,00l-ew-pet 1,50l-ew-pet
meaning, I would put "-" or "_" as seperator between parts AND use a constant amount of chars for each file to get a "column" adjusted view of those - and probably, with constanting the amount, even nautilus would sort decently. I am basically suffering that nautilus ignores the "_" "!" prefixing...

The more I think about it, sorting order would be something a good filesystem should record for each directory and this info should even be passed into eg. 7z or zipfiles all the way, so it is retained when going to someone else. Should file a brainstorm thing here - anybody know if zfs has such options yet?

Changed in nautilus:
importance: Unknown → Medium
Revision history for this message
Embridioum (embridioum) wrote :

I have the same issues but with folders named only with letters.

In my music folder I get "Nightingale" before "Night In Gales" and "Darkane" before "Dark Funeral".

Revision history for this message
Marcello Romani (marcello-romani) wrote :

Linux ced-desktop 2.6.32-31-generic #61-Ubuntu SMP Fri Apr 8 18:24:35 UTC 2011 i686 GNU/Linux
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.04
DISTRIB_CODENAME=lucid
DISTRIB_DESCRIPTION="Ubuntu 10.04.2 LTS"

Here's what I'm seeing right now:

Nautilus:
0,2LMW
0,5LMW
0,5LMWPET
0,33LMW
1,0LEWPET
1,5LEWPET

ls|sort:
0,2LMW
0,33LMW
0,5LMW
0,5LMWPET
1,0LEWPET
1,5LEWPET

Revision history for this message
Marcello Romani (marcello-romani) wrote :

Please raise the importance of this bug to "critical". It's embarrassing!

Changed in nautilus (Ubuntu):
assignee: Ubuntu Desktop Bugs (desktop-bugs) → nobody
summary: - When sorting alphabetically by file name, 0,5LMW is displayed before
- 0,33LMW
+ Sorting by name doesn't work with digits
summary: - Sorting by name doesn't work with digits
+ Sorting by name doesn't work with digits or special chars
summary: - Sorting by name doesn't work with digits or special chars
+ Sorting by name doesn't work well with digits or special chars
Revision history for this message
Simon Arlott (sa.me.uk) wrote :

The Gnome developers appear to be unwilling to fix this after nearly 8 years. I've attached an example of the issue where it is clear that the sort order is wrong, even for proponents of natural sort ordering.

It can be fixed for Nautlius by changing g_utf8_collate_key_for_filename() to g_utf8_collate_key() nautilus-3.10.1/libnautilus-private/nautilus-file.c but this only affects Nautilus windows. File dialogs still use the wrong sort order.

In glib, g_utf8_collate_key_for_filename() is broken for anything with leading zeros (it sorts 2009.1 before 2009.05) so it doesn't even get natural ordering correct.

The sort order of g_utf8_collate_key_for_filename() is too aggressive in splitting up filenames into separately ordered components, which makes it inconsistent with user expectations for highly structured filenames.

Some sort of desktop-wide "use natural sort order" setting is required to allow the behaviour to be adjusted. An environment setting for glib would do (although the change wouldn't be effective immediately).

Revision history for this message
hergo (hergo-pad) wrote :

You can track a bug request for glib in https://bugzilla.gnome.org/show_bug.cgi?id=754777
and you can find a partial hack at https://github.com/heralight/GlibSortFileNameHackLibrary

Revision history for this message
Grizzly (sven-witterstein) wrote :

Well, nice to see something's going on. The sort just sucks. Why not AT LEAST provide the option to chose between plain ascii-codepage-utf-8-number-in-the-charmap-style sort and this broken natural sort?

Revision history for this message
Tomas Petricek (tpetricek) wrote :

I simply don't believe this is a design choice:
a a.txt
aa a.txt
a b.txt
k a.txt
k b.txt
kk a.txt

There should be at least an option for the simple alphabetical ordering.
Also, I believe the priority should be higher since listing files is the main function of a file browser...

Revision history for this message
Mitch Butler (mitchelbbutler) wrote :

I'm not sure if this is the same bug or a different one. I am using ubuntu 14.04 LTS. I have a directory containing other directories. They sort correctly with "ls -l". But they show up in Nautilus as:
    20190428_96a11107 <- wrong order
    20190428_1271f6a8
    20190428_4314187e
    20190428_a4b67026
    20190428_a9637c2a
    20190428_bd912fd3
    20190428_c7b6ee8a <- wrong order
    20190428_c408cf3c
    20190428_ec90884e

I am not aware of any hidden special characters in the names. It is easy to reproduce on my machine. Just go to an empty folder and do:
    touch 20190428_1271f6a8
    touch 20190428_4314187e
    touch 20190428_96a11107
    touch 20190428_a4b67026
    touch 20190428_a9637c2a
    touch 20190428_bd912fd3
    touch 20190428_c408cf3c
    touch 20190428_c7b6ee8a
    touch 20190428_ec90884e

They sort correctly with "ls -l", but not with Nautilus.

I haven't tried a more recent version of ubuntu. Should I report this somewhere else?

Revision history for this message
Roadowl (roadowl) wrote :

Most elegant solution to this abomination: https://github.com/heralight/GlibSortFileNameHackLibrary

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.