I would like an alias that gives a directory listing in dictionary order with "." files first. It seems that one few ways to accomplish this devoid of writing my own script (which isn't a real problem) is to set the locale with LC_ALL="C". (This is per the sorting man page, and multiple other sites).

However setting the locale to "C" can (and does) cause some software installations to break. So my short term solution is akin to this (This is without the additional ls options, for brevity):

alias ls='(LC_ALL="C"; /bin/ls)'

But this does not allow arguments to be "passed" into the subshell.

This of course does not work:

alias ls='(LC_ALL="C"; /bin/ls $*)'

Is there a way to handle this with a simple alias? (As opposed to writing a shell script/function, which I can do).


You don't need a subshell. You can change the environment just for the following command by prepending the command with the variable assignment without semicolon. Compare for example the output of

LC_ALL=C env | grep LC_ALL

with the output of

env | grep LC_ALL

So, to cut a long story short, the following alias should work for you:

alias ls='LC_ALL=C /bin/ls'

I used /bin/ls as in your example, but as pointed out by Kamil Maciorowski in a comment to another answer, your typed in ls command might be an alias, too, so maybe you should also consider that alternative:

alias ls='LC_ALL=C ls'
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.