11

I have many folders in my home directory that have names that begin with special characters such as _OLD_500GB_HD or !FolderIWantToSeeAtTheTop, but for some reason these folders are sorted according to their first alphanumeric character rather than the leading special character.

So how can I force the folder to not ignore the special character, or how else can I make the sort view organize certain folders at the top or bottom of the sort? Thanks.

  • Related, not duplicate: https://askubuntu.com/questions/239371/how-do-i-list-folders-with-underscores-first/243012#243012 – Kevin Bowen Jul 19 '22 at 21:18

1 Answers1

11

Nautilus follows your locale's collation rules when sorting files by name. The rules for the English locales specify that punctuation, case and accents are less important than what letters occur in the string.

If you want collation to be equivalent to strcmp() sort order (i.e. do a simple comparison of the code point values for the characters in the string), you can switch to the legacy C locale for collation.

This can be done by editing ~/.profile and adding (or modifying) a line like the following:

export LC_COLLATE=C

When you next log in, the change should take effect in all programs that were using the locale collation order.

  • 2
    Perfect. Thanks, James.

    Would it be asking Nautilus too much to also maybe ignore case? In other words is there a way to get picky, i.e. ls --group-directories-first combined with sort --ignore case?

    – Jason Hartley Mar 25 '12 at 01:14
  • 2
    As I said, Nautilus doesn't implement the sorting algorithm: it defers to the locale's collation algorithm. If there were a locale with an algorithm like that then it would use it. Creation of new locales is pretty heavy weight though, so it isn't trivial. – James Henstridge Mar 25 '12 at 02:57
  • Perfect! I had a similar problem with the program sort. It was unable to sort correctly a csv file with tabs. This solved the problem. – xerostomus Jan 13 '17 at 06:22
  • For a temporary method that doesn't require logging out: killall nautilus && LC_COLLATE=C nautilus & – Mark Jeronimus Jun 16 '20 at 17:03
  • @MarkJeronimus appreciate the faster testing approach. unfortunately LC_COLLATE=C or POSIX didn't change the sorting order of underscores. – Jason Harrison May 09 '23 at 17:40