macOS: ls command stopped working
Which program really messed up with my
ls
cmd in the first place, is it python?
Your ls
command is untouched. Your ls
alias most likely comes from an erroneous Bourne Again shell setup.
Note that your ls
alias is running a command named grc
, via another alias named colourify
. This comes from Radovan Garabík's Generic Colourizer, whose Bourne Again shell aliases (in grc.bashrc
) and Z shell aliases (in grc.zsh
) set up an alias named ls
.
Somewhere, in an rc file, you are adding these aliases to your interactive Bourne Again shell, per recommendations like this Stack Overflow answer.
The Z shell alias is
alias ls="grc --colour=auto ls"which passes the
--colour-auto
option to the grc
command, which is the command that takes that option.
However, The Bourne Again shell alias is
alias ls='colourify ls --color'which is (via the
colourify
alias) effectively alias ls='grc -es --colour=auto ls --color'which is both running the output of the
ls
command through a colourizer and trying to get the ls
command to colourize its output.
The basic problem is that the author of these Bourne Shell aliases (which was Isaias Piña from Oracle in May 2016) hasn't catered for running the Bourne Again shell on anything other than a Linux operating system, probably expecting that if you are using MacOS you are using something like Oh My Zsh. An additional problem is that the author hasn't allowed for grc
to colourize the output of ls
and is, rather, expecting ls
to colourize its own output.
So you have a number of options:
- Find where you are adding these aliases and fix Isaias Piña's erroneous
ls
alias to use the-G
option on MacOS. - Find where you are adding these aliases and fix Isaias Piña's erroneous
ls
alias to not use any option and instead rely upon the colourizer'sconf.ls
file to do its actual job; as Tom Mulder has. - Find where you are adding these aliases and remove Isaias Piña's erroneous
ls
alias entirely, using theCLICOLOR
environment variable for colourization instead; as Noel B Alonso does. - Find where you are adding these aliases and remove Isaias Piña's erroneous
ls
alias entirely, using your ownls
alias; as Arthur Nisnevich does. - Uninstall the Generic Colourizer entirely.
- Use the Z shell.
macOS (Darwin) ls
doesn't support the --color
option. Did/do you have another copy of coreutils
installed from something like homebrew, macports, or pkgsrc that is now gone or changed order in your PATH
?
I just updated iTerm2 to version Build 3.0.14
and ran into this issue. The command ls
from coreutils was no longer in my path. After running:
brew install coreutils
and opening a new shell the problem was fixed. I have the following alias in my ~/.bashrc:
export LS_OPTS='--color=auto'
alias ls='ls ${LS_OPTS}'