I am trying to find a way to get either the stock macOS ls
or (more likely) the GNU ls
a.k.a. gls
to show my files & folders in case insensitive order.
All of my efforts have resulted in lowercase letters being sorted after the uppercase letters.
⚠️ There are lots of outdated answers which no longer work!
This same question was asked on this forum in October 2011 (and in August 2013 on Stack Overflow), but those answers no longer work on macOS in 2020.
What I've tried that does not work:
-
LC_COLLATE
does not seem to have any effect. I have tried these variations:LC_COLLATE="en_US.UTF-8" LC_COLLATE="cs_CZ.ISO8859-2" LANG="en_US.UTF-8" LC_COLLATE="en_US.UTF-8"
There was no noticeable effect at all.
-
Apparently
ls -f
orgls -U
used to work for HFS+, although the output was supposed to be "unsorted", but apparently somehow in HFS+ "unsorted" was ¿accidentally? ¿coincidentally? case-insensitive? I guess? Whatever the reason, it no longer works, presumably because we’re using APFS now. -
”Just pipe it through
sort -f
!” was never really an answer, but someone always seems to suggest it anyway. I want to be able to use all of the other features ofls
/gls
including color and-C
which doesn’t work if we have to pipe through another command.
Is there some hidden method out there that I might have missed? Or does this functionality is actually not possible? The latter would seem extremely odd to me, but stranger things have happened, I guess.
P.S. – I use zsh
as my default shell anyway, so if there’s a way to replicate this with zsh
that would be OK too.
Best Answer
If done properly the LC_COLLATE method works:
Example:
So simply add
export LC_COLLATE="cs_CZ.ISO8859-2"
to your .zprofile/.zshrc/... and restart Terminal.If you use this locale you might experience some irregularities in shell outputs/history files etc.
Here (using mixed us_en/de_de locales im macOS) I got some irregular entries in the command history (i.e. .zsh_history) after entering German umlauts.
Probably the best idea then: create a new custom LC_COLLATE file.