Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Somewhere along the way I screwed up my ls command and now I get this ordering when running

$ ls -AhHl --color=auto
-rwxr-xr-x 1 clang clang  640 Mar  1 02:46 apple-touch-icon-precomposed.png
-rwxr-xr-x 1 clang clang  784 Jul 12 02:54 crossdomain.xml
-rwxr-xr-x 1 clang clang 1.2K Mar  1 02:46 favicon.ico
drwxr-xr-x 8 clang clang 4.0K Jul 12 23:50 .git
-rw-r--r-- 1 clang clang   17 Feb 29 19:48 .gitignore
-rwxr-xr-x 1 clang clang 1.4K Jul 12 02:54 humans.txt

What did I do that made ls ignore the dotfiles and instead order by first letter?

If it helps you can view all my dotfiles here

Output of locale:

$ locale
share|improve this question
up vote 29 down vote accepted

Try adding

export LC_COLLATE="C"

in your dotfiles, or changing the LC_ALL assignment to:

export LC_ALL="C"

This controls the way sorting on character level works — while the default would be to sort dotfiles inline, this will make sort list dotfiles first.

To go further, quoting the GNU Coreutils manual (emphasis mine):

If you use a non-POSIX locale (e.g., by setting LC_ALL to en_US), then sort may produce output that is sorted differently than you're accustomed to.

In that case, set the LC_ALL environment variable to C. Note that setting only LC_COLLATE has two problems. First, it is ineffective if LC_ALL is also set. Second, it has undefined behavior if LC_CTYPE (or LANG, if LC_CTYPE is unset) is set to an incompatible value. For example, you get undefined behavior if LC_CTYPE is ja_JP.PCK but LC_COLLATE is en_US.UTF-8.

share|improve this answer
Setting LC_ALL="C" did the trick! Thanks for the quick response – clang1234 Jul 13 '12 at 1:20
Setting LC_ALL="C" will ls foreign language (e.g. Japanese) unicode filenames as ???????? – ohho Jul 23 '13 at 8:31
Note that by adding export LC_ALL="C" to your dotfiles you'll effectively lose support for your actual locale across all locale-aware utilities. While the printing problem that @ohho points out could be remedied with Faroul's answer, you'll introduce sorting problems: sorting will happen by byte value only, resulting in sorting that is (a) unexpectedly case-sensitive, and (b) invariably places accented chars. after all non-accented ones. – mklement0 Nov 3 '14 at 4:16

To avoid any system wide changes without real need, one can change only the way how ls works for the current user by adding the alias to the .bashrc:

alias ll='LC_COLLATE=C ls -alF'

This sorts dot files first, allows to properly handle (show and sort) "uncommon" character sets like cyrillic. The only culprit that the sorting will be case-sensitive.


share|improve this answer
This is the best answer here by far – Engineer Dollery Mar 29 '15 at 13:16
Beautiful. Much better than changing the system-wide configuration (which can cause you problems with some python modules). – Gui Ambros May 28 at 19:56



works fine for me - umlauts and "ls -la" lists dot-files first.

share|improve this answer
dot files are listed first, but now file names that starts with a uppercase letter are listed before those that starts with a lowercase. – Chnossos Aug 2 '14 at 20:47
+1 for coming closer than the accepted answer, but to summarize the limitations: the sorting will become case-sensitive, and foreign characters - while now printed correctly due to UTF-8 - won't be sorted correctly. – mklement0 Nov 3 '14 at 4:16
C.UTF-8 is an invalid locale, so locale reverts back to C. You still lose UTF-8 support. In fact, it's even worse since LC_ALL=C mostprograms display most multibyte characters correctly, but with LC_ALL=something_invalid some programs don't (like `ls). – Carpetsmoker Jun 7 '15 at 23:54

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.