18

I have the following directory listing on a Debian Linux system. However, one strange thing is that the file populate.sql does not seem to be sorted with the rest.

-rw-r--r-- 1 user1 user1 10004 Jul 28 13:16 populate2.sql
-rw-r--r-- 1 user1 user1 10244 Jul 28 13:16 populate3.sql
-rw-r--r-- 1 user1 user1 10359 Jul 28 13:16 populate4.sql
-rw-r--r-- 1 user1 user1 11618 Jul 28 13:16 populate5.sql
-rw-r--r-- 1 user1 user1 11654 Jul 28 13:17 populate6.sql
-rw-r--r-- 1 user1 user1 12198 Jul 30 16:20 populate7.sql
-rw-r--r-- 1 user1 user1 12286 Aug 10 00:10 populate8.sql
-rw-r--r-- 1 user1 user1 12331 Aug 19 08:48 populate9.sql
-rw-r--r-- 1 user1 user1 12401 Aug 20 14:58 populatea.sql
-rw-r--r-- 1 user1 user1 12460 Aug 22 01:09 populateb.sql
-rw-r--r-- 1 user1 user1 12503 Aug 22 17:13 populatec.sql
-rw-r--r-- 1 user1 user1 13341 Aug 23 23:23 populated.sql
-rw-r--r-- 1 user1 user1 13414 Aug 27 23:01 populatee.sql
-rw-r--r-- 1 user1 user1 16064 Aug 31 00:03 populatef.sql
-rw-r--r-- 1 user1 user1 17529 Sep 16 15:38 populateg.sql
-rw-r--r-- 1 user1 user1 19348 Sep 19 22:50 populateh.sql
-rw-r--r-- 1 user1 user1 21033 Sep 27 20:46 populatei.sql
-rw-r--r-- 1 user1 user1 21024 Sep 28 00:02 populatej.sql
-rw-r--r-- 1 user1 user1 22505 Sep 28 22:55 populatek.sql
-rw-r--r-- 1 user1 user1 23831 Oct  5 21:24 populatel.sql
-rw-r--r-- 1 user1 user1 23665 Nov  2 22:16 populatem.sql
-rw-r--r-- 1 user1 user1 23513 Nov  4 21:53 populaten.sql
-rw-r--r-- 1 user1 user1 27191 Nov 19 14:55 populateo.sql
-rw-r--r-- 1 user1 user1 30142 Nov 28 17:51 populatep.sql
-rw-r--r-- 1 user1 user1 30853 Dec 10 14:49 populateq.sql
-rw-r--r-- 1 user1 user1 33690 Dec 11 23:43 populater.sql
-rw-r--r-- 1 user1 user1  9945 Jul 28 13:16 populate.sql
-rw-r--r-- 1 user1 user1 38696 Jan 16 22:27 populates.sql
-rw-r--r-- 1 user1 user1 38696 Jan 16 22:27 populatet.sql

At first I thought it might be because of a hidden character or something, but I can't think of a hidden character that would come between r and s. Also, if I type vim populate.sql into the command prompt it opens the correct file which is further evidence there isn't a strange character there.

Any ideas why populate.sql is not being sorted correctly?

  • 1
    Is this on a Linux system or Mac OS/BSD? (The ls versions are different.) It looks almost like the period is being ignored for purposes of sorting, which is interesting. – Wildcard Jan 17 '18 at 4:39
  • @Wildcard It is on Debian Linux – kojow7 Jan 17 '18 at 5:48
27

LC_COLLATE with any Unicode-aware collation, e.g. en_US.UTF-8 results in a sort order that ignores punctuation. Consequently, populate.sql sorts as populatesql after populatersql but before populatessql.

If you want to see this behavior change, try running LC_COLLATE=C ls -al, and it will be sorted in C sorting order (by specific bytes without regard to any codepoints or locales).

  • 2
    Interesting. Are recent versions of Debian like that by default or is there a setting that I would have changed to enable that? I do not recall ever having encountered this 'problem' before? – kojow7 Jan 17 '18 at 5:51
  • I do not know how recent or not it is, but I do believe the default locale used to always be C. – David Jan 17 '18 at 5:55
  • 1
    When none of the LC_*, LANG variables are set, the default locale is and has always been C/POSIX, but most systems have a default locale configured and users can generally specify one at login time as well. That GNU libc locale sorting behaviour as found on Debian has been like that for certainly over 10 years. – Stéphane Chazelas Jan 17 '18 at 12:31
  • Just for reference, I did try a new Debian install and yes, it does ignore punctuation in its sort order by default. In /etc/default/locale it says LANG="en_US.UTF-8". – kojow7 Jan 17 '18 at 15:17

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.