ls: illegal option

I just updated my system and found ls command did not work. It returns the error message "ls: illegal option -- -" under all directories. How to fix it?User uploaded file

iMac, Mac OS X (10.6.8)

Posted on Mar 8, 2012 11:28 AM

Reply
6 replies

Mar 8, 2012 12:20 PM in response to mjchen

Are you just hitting return at the end of line?


Check the terminal preferences, Encodings. In fact go through all your terminal preferences to see if they make sense (particularly Settings, Advanced for terminal type -- I use xterm, character encoding).


Also, is ls the only command this happens with, or all terminal commands? If just ls then is it possible you aliased it in one of the bash startup scripts to something with an illegal option? I'm assuming you know what I am talking about with respect to the bash startup scripts.

Jan 17, 2014 8:27 AM in response to tomachi

They're referring to a setting in a bashrc configuration file.


Here is a similar configuration for a linux bash kernel (which is very similar) where they set the following:


alias ls='ls --color=auto'


Note the 'alias' not 'alis'.


So it appears that through some process, the definition for 'ls' was changed. I had this same issue and it turns out I had to check all locations where this definition could be. Those places possibly include the following (if they exist):


/etc/bashrc
~/.profile

~/.bash_profile

~/.bashrc


Check if any of those files have an additional entry for the 'ls' command.

Feb 4, 2014 3:30 AM in response to computermatt

OK cool, thanks I found the /etc/bashrc but no mention of any colour presets etc.


I then checked ~/.profile and found this:

[ "$TERM" = "xterm" ] && TERM="xterm-256color"

alias ls='ls --color'

So I made it like this:

alias ls='ls --auto'


Saved and restarted Terminal, but it still gives this message:

jb:~ tom$ ls

ls: illegal option -- -

usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]

BUT THEN I FIXED IT: by just deleting the ~/.profile file altogether! 😁 😁


So it appears this line in this file is definitely causing the issue. It would be nice to know if deleting the file is bad but for now I'm stoked to be able to type is "ls" once again!


Thanks!!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

ls: illegal option

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.