11

On my macOS (10.11.6) terminal, I did some installations on python virtual env. After that my ls command stopped working. It is giving an error:

$ ls
ls: illegal option -- -
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]

$ alias ls
alias ls='colourify ls --color'
2
  • 1
    Just unalias ls
    – kmkaplan
    Commented Feb 5, 2017 at 7:37
  • unalias ls works but then I've to run this command each time I open a new terminal window. Which program really messed up with my ls cmd in the first place, is it python?
    – Shah-G
    Commented Feb 5, 2017 at 7:42

7 Answers 7

6

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's conf.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 the CLICOLOR 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 own ls alias; as Arthur Nisnevich does.
  • Uninstall the Generic Colourizer entirely.
  • Use the Z shell.
1
  • 1
    I'm using simple bash. I had two lines added to my ~/.profile and they were working for ~5 years: alias ll='ls -GFhl' source "$(brew --prefix)/etc/grc.bashrc" The last couple of days, I added imagemagick7 and brew updates happened. They may have caused some of the ls troubles
    – Shah-G
    Commented Feb 6, 2017 at 6:38
4

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}'
3

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?

1
  • But my ls was working with --color option for over 5 years. I had homebrew but no coreutils installed.
    – Shah-G
    Commented Feb 6, 2017 at 6:40
1

Using homebrew, install coreutils and add the coreutils to the PATH:

brew install coreutils
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"

Source:https://github.com/sorin-ionescu/prezto/issues/966.

0

Homebrew updated to new version of grc 1.10_1 and this issue is solved.

0

In my case, it turned out I was attempting to delete a whole lot of .zip files with dashes in their names.

man rm mentions using -- to prevent the command from processing further options.

rm -rf -- *.zip

Did the trick.

0
if ls --help 2>&1 | grep -q -- --color
then
    alias ls='ls --color=auto -F'
else
    alias ls='ls -FG'
fi

This magic snippet from https://unix.stackexchange.com/a/342168/287064 fixed it for me.

I think it has to do with macOS's BSD vs GNU versions of ls.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .