Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

So as pretty much everyone, before using Ubuntu I used a Windows machine, and one of the things I got used to in Windows was to use the underscore as the first character of a folder name as some sort of special marking so that it would be appear first on listing, both in command line and file explorer.

For instance, in my eBooks folder (in Windows) looks something like this:


but in Ubuntu's Nautilus it looks like this:


What is happening is that it is completely ignoring the underscore and it treats "_read" as "read" and therefore not listing it in first as wished.

I have tried setting the environment variable LC_COLLATE to C. This helps somehow since it lists the underscore together, but at the end, and not at the beginning.


share|improve this question
can you include a screenshot? –  philshem Jan 10 '13 at 3:21
Possible duplicate of askubuntu.com/questions/115741/… although I think @maggotbrain's answer is better than the one presented there. –  rudivonstaden Jan 14 '13 at 10:47
add comment

1 Answer 1

Since you have not specified the locale that you are currently using, this solution assumes that you are using en_US.UTF-8 as your default.

You can check this by running the command locale from the command line(Ctrl+Alt+t).

The variable that affects the sorting order of files is called LC_COLLATE.

According to the Ubuntu help pages, the LC_COLLATE variable determines "How strings (file names...) are alphabetically sorted. Using the "C" or "POSIX" locale here results in a strcmp()-like sort order, which may be preferable to language-specific locales."

The sort order will need to be changed from LC_COLLATE="en_US.UTF-8" to LC_COLLATE=C.

From the command line(Ctrl+Alt+t), enter:

update-locale LC_COLLATE=C

Note: You need to log out of your system and log back in order for the changes to take effect. Running the locale command, again, should show that the LC_COLLATE variable, along with the sorting order of ls -l, has been successfully changed.

share|improve this answer
should that not be update-locale LC_COLLATE=C? –  rudivonstaden Jan 14 '13 at 8:50
also note that you need to log out for your locale changes to take effect. –  rudivonstaden Jan 14 '13 at 10:23
I have already set the LC_COLLATE to C, as I have described in the last paragraph of my question. Still, I am getting different results in both the terminal and the nautilus explorer and I have rebooted the computer in the meanwhile. Any idea why that's happening? –  nunos Jan 14 '13 at 14:37
@nunos Do you have any aliases set for ls in your .bashrc? –  Kevin Bowen Jan 15 '13 at 1:02
@nunos Interesting. What files system type are you checking this on? The only place that I have issues with ls -l sorting is on an ntfs formatted drive which doesn't appear to honor the LC_COLLATE variable. All of my ext3 filesystems seem to respect that setting using the ls command as well as in Thunar and Nautilus. –  Kevin Bowen Jan 15 '13 at 3:53
show 2 more comments

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.