Case-insensitive ls sorting in Mac OSX

It might not be possible:

Taking a look at the source code for ls, it uses strcoll to sort the filenames, and so should respect LC_COLLATE.

Some postings online suggest that the locales in BSD (and Darwin/OS X) are somewhat broken compared to those in Linux. I wrote a quick sorting program of my own which explicitly set it's locale and tested it using both the en_US.UTF-8 and C locales on my machine (Mac OS 10.6.3) and a university machine (Linux, FC11?). While sorting works as expected on the linux machine, ("a B c" vs "B a c"), the mac always sorts them as "B a c".

Source: http://ask.metafilter.com/130292/CaseInsensitive-LS-on-Mac-OS-X

ORIGINAL ANSWER

This command does not sort dot files, but shows additional directory listings

ls -f1 

I got close to this:

.
..
.stuff
foo
Foobar
MyStuff
test.txt

Update as of Aug 1, 2021:

ls -alFG

Explanations:

-a      Include directory entries whose names begin with a dot (.).
-l      (The lowercase letter ``ell''.)  List in long format.  (See below.)  A total sum for all the file sizes is output on a line before the long
        listing.
-F      Display a slash (`/') immediately after each pathname that is a directory, an asterisk (`*') after each that is executable, an at sign (`@')
        after each symbolic link, an equals sign (`=') after each socket, a percent sign (`%') after each whiteout, and a vertical bar (`|') after
        each that is a FIFO.
-G      Enable colorized output.  This option is equivalent to defining CLICOLOR in the environment.  (See below.)

Old:

I know this has been answered but this work best for me:

ls -f1 -alFG

It lists all details and sorts them by ignoring case.


This has been bugging me for awhile now, and I finally got it sorted (heh). After trying a bunch of suggestions that didn't work, here's what did.

If you're willing to install MacPorts (or Homebrew, or Fink), the GNU version of ls does exactly what you want. I use MacPorts, myself, so that's the approach I'll explain:

  1. Download and install MacPorts:

    http://www.macports.org

  2. Install the GNU Coreutils package:

    sudo port install coreutils

  3. You should now have GNU ls: gls. Try it in a directory that contains items that start with both uppercase and lowercase letters:

    gls -U

    (The -U option actually means "unsorted", but on OS X that has the desired effect of making it case insensitive.)

  4. Add this alias in your .bash_profile so the regular ls will work the way you want it to (I like the color output, but you can omit that if you want; you only need the -U):

    alias ls='gls -U --color'

Note that the -U option probably won't work on other platforms. In OS X, it always seems to do the right thing (maybe because HFS+ is effectively case-insensitive -- "case-aware", technically), but if you try it on a Linux box, the results will most likely just not be sorted at all.