How can I make the ls
command in Max OS X Lion sort files and directories similar to how Ubuntu Linux does (case-insensitive, directories NOT on top, dot files NOT on top)? Ideally I'd like to do this without piping output to another command such as sort.
For example, I want to see:
foo
Foobar
MyStuff/
.stuff/
test.txt
instead of:
.stuff
Foobar
MyStuff/
foo
test.txt
In Linux, ls
sort order is controlled by the system's locale, specifically LC_COLLATE
. When LC_COLLATE=en_US.UTF-8
, ls will sort items like I want. When LC_COLLATE=C
, ls
will sort similar to OS X.
LC_COLLATE
is set to en_US.UTF-8
in OS X, but ls
still sorts the old POSIX
way. Does anyone know how I can make this behave more like Linux?
sort
andls
also respects LC_COLLATE, but the LC_COLLATE definition for locales likeen_US.UTF-8
is just a symlink that makes it behave like C locale. See mike's answer below for more details.