Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
$ export LC_ALL=en_US.UTF-8
$ ls -al
total 24
drwxr-xr-x 6 pi pi 4096 Jul 23 16:34 .
drwxr-xr-x 9 pi pi 4096 Jul 23 16:33 ..
drwxr-xr-x 2 pi pi 4096 Jul 23 16:33 .A
drwxr-xr-x 2 pi pi 4096 Jul 23 16:33 B
drwxr-xr-x 2 pi pi 4096 Jul 23 16:33 .C
drwxr-xr-x 2 pi pi 4096 Jul 23 16:34 你好嗎

When I change LC_ALL to C, dot files are listed first, by unicode filenames are unreadable:

$ export LC_ALL=C
$ ls -al
total 24
drwxr-xr-x 6 pi pi 4096 Jul 23 16:34 .
drwxr-xr-x 9 pi pi 4096 Jul 23 16:33 ..
drwxr-xr-x 2 pi pi 4096 Jul 23 16:33 .A
drwxr-xr-x 2 pi pi 4096 Jul 23 16:33 .C
drwxr-xr-x 2 pi pi 4096 Jul 23 16:33 B
drwxr-xr-x 2 pi pi 4096 Jul 23 16:34 ?????????

How can I make “ls” show dotfiles first and preserve unicode filenames?

UPDATE, solution found (thanks to Ярослав Рахматуллин's answer):

$ cat /etc/default/locale 
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LC_COLLATE=C

rebooted, show env:

$ env | grep -E 'LANG|LC'
LC_COLLATE=C
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE=en_US.UTF-8

sorting as expected:

$ ls -al
total 24
drwxr-xr-x 6 pi pi 4096 Jul 23 16:34 .
drwxr-xr-x 9 pi pi 4096 Jul 24 08:29 ..
drwxr-xr-x 2 pi pi 4096 Jul 23 16:33 .A
drwxr-xr-x 2 pi pi 4096 Jul 23 16:33 .C
drwxr-xr-x 2 pi pi 4096 Jul 23 16:33 B
drwxr-xr-x 2 pi pi 4096 Jul 23 16:34 你好嗎

no warning from perl -v:

$ perl -v

This is perl 5, version 14, subversion 2 (v5.14.2) built for arm-linux-gnueabihf-thread-multi-64int
(with 80 registered patches, see perl -V for more detail)

Copyright 1987-2011, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
share|improve this question
    
Which terminal emulator and version of coreutils do you have? –  Ярослав Рахматуллин Jul 24 '13 at 3:56

2 Answers 2

up vote 1 down vote accepted

ohho, your assumption seems incorrect. That is, I can list chinese files even without LC_ALL.

wraptor: ~/tmp/god-damn-mongorians
$ LC_ALL=C

$ ll
-rw-r--r-- 1 0K 2013-07-23 12:50 ??????????????????

$ unset LC_ALL

$ ll
-rw-r--r-- 1 0K 2013-07-23 12:50 我很好,谢谢

$ LANG=en_US.iso-8859-1

$ ll
-rw-r--r-- 1 0K 2013-07-23 12:50 ?▒???▒??好?▒??谢?谢

To acheive your goal you want to set LANG (or LANGUAGE) to a locale with a UTF encoding and set LC_COLLATE as our swedish friend suggested.

$ ll -a
drwxr-xr-x+ 1 0K 2013-07-23 12:50 .
drwxr-xr-x  1 0K 2013-07-23 12:48 ..
-rw-r--r--  1 0K 2013-07-23 12:50 ?▒???▒??好?▒??谢?谢

$ LANG=en_US.utf-8
$ LC_COLLATE=C    

$ ll -a
drwxr-xr-x+ 1 0K 2013-07-23 12:50 .
drwxr-xr-x  1 0K 2013-07-23 12:48 ..
-rw-r--r--  1 0K 2013-07-23 12:50 我很好,谢谢

update: Created three folders as per request in comment.

Mintty

Launched as a native windows binary.

mintty

URxvt

Launched from laptop, displayed under Xwin in Cygwin. Notice that the files are sorted "correctly" when LC_COLLATE is set.

urxvt

Ubuntu virtual console in a VM

VC

share|improve this answer
    
please make 3 folders: mkdir .A mkdir B mkdir .C, besides showing unicode characters, I want to list dotfiles first. –  ohho Jul 24 '13 at 1:51
    
@ohho Sure. Done. –  Ярослав Рахматуллин Jul 24 '13 at 3:52
    
thank you! solution updated in question. –  ohho Jul 24 '13 at 4:23
    
不客气 :) I'm so tired of encoding issues... –  Ярослав Рахматуллин Jul 24 '13 at 4:34

The locale C does not do UTF-8. If you use a UTF-8-aware locale with the proper collation settings, then the ls invocation should behave as you expect. (You can build your own locale, if you find yourself doing this sort of thing often. For an example of a locale which brings in parts from other locales, you may want to look up en_SE.)

If you only want to sort according to the C locale, you don't need to set LC_ALL (which is a global override for all other LC_* settings, hence the name) but can simply set LC_COLLATE, which affects sorting (the link is for AIX, but the overall description is general enough). In that case, LC_COLLATE=C ls -al should be close enough to what you want.

share|improve this answer
    
if I unset LC_ALL, unicode filenames will not be visiable. Which one of LC_* controls filename encoding? –  ohho Jul 23 '13 at 10:16

Your Answer

 
discard

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.