My morning coffee hadn't reached my brain yet when I forgot the quotes in:

alias grep="grep --color=always"

so instead I typed:

alias grep=grep --color=always

leaving me with:


in my aliases.

When I try to cleanup the --color=always using unalias --color I get:

bash: unalias: --: invalid option
unalias: usage: unalias [-a] name [name ...]

I tried escaping, quoting and begging, but I can not figure out how to make the commando unalias cleanup the mess.

(I know a restart will do the trick but surely there must be another way)

  • 13
    Ha ha, now I got it stuck in mine also, working on it EDIT: Looks like choroba's answer worked for me Commented Mar 2, 2017 at 10:05
  • 9
    Kind of reminds me of the old echo > \\?\c:\windows\x., or that time I rm -rf * ~ by accident.
    – Jason C
    Commented Mar 3, 2017 at 1:08

3 Answers 3


You can avoid POSIX compliant systems interpreting dashes in commands by adding -- before any arguments.

mtak@frisbee:~$ alias grep=grep --color=always
mtak@frisbee:~$ alias | grep color
alias --color='always'

mtak@frisbee:~$ unalias -- --color
mtak@frisbee:~$ alias | grep color

This also works with other utilities, let's say you have a file named -bla. If you try to remove it with rm you will get the following error:

mtak@frisbee:~$ ls -- -bla
mtak@frisbee:~$ rm -bla
rm: invalid option -- 'b'
Try 'rm ./-bla' to remove the file '-bla'.
Try 'rm --help' for more information.

By using -- before the filename, you will remove the file:

mtak@frisbee:~$ rm -- -bla
mtak@frisbee:~$ ls -- -bla
ls: cannot access '-bla': No such file or directory
  • 19
    Though it's worth noting that for files, an equally valid method is to use a path to the file that avoids this; so you can use ls ./-bla and rm ./-bla (or specify the full paths, whatever's easier in your case). Obviously this doesn't work for aliases though!
    – Muzer
    Commented Mar 2, 2017 at 11:52
  • 1
    pubs.opengroup.org/onlinepubs/009695399/basedefs/… Guideline 10
    – user115383
    Commented Mar 5, 2017 at 1:20

Just use the same trick you used to set the alias

unalias whatever --color
  • 9
    works indeed, +1 but the other solution is a bit cleaner :)
    – Requist
    Commented Mar 2, 2017 at 10:16
  • 1
    Indeed, of course :-)
    – choroba
    Commented Mar 2, 2017 at 10:19
  • unalias unalias --color
    – Cœur
    Commented Mar 3, 2017 at 10:40

Fast solution

To fix both the wrong aliases you may simply run

unalias grep --color

Understanding what's happened

You give the wrong command alias grep=grep --color=always without "...".

  • You set two aliases --color and grep; indeed you can read it on the left side of your output (all at the left of the = is a aliased command):


    so you need to unset both.

  • Why this happened?
    The ... in the synoptic of alias means that is possible to do multiple assignation in one line:

    alias: alias [-p] [name[=value] ... ]

    In the output of help alias you can read the synoptic but from man bash you can read that is possible in the same line even to list and assign at the same time:

    When arguments are supplied, an alias is defined for each name whose value is given. A trailing space in value causes the next word to be checked for alias substitution when the alias is expanded. For each name in the argument list for which no value is supplied, the name and value of the alias is printed...

  • You have problems to unset the first one --color alone.
    This because it is interpreted as options for alias by your shell; to avoid this you need communicate to your bash shell that what is following it is not an option.

  • The Holy Grail of Linux: man, in this case man bash that is a coffer filled with treasures useful in situation like this.
    You can read from man bash:

    -- A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and arguments. An argument of - is equivalent to --.

    As reported in other answer the POSIX way is to use the special character combination --.

    unalias -- --color
  • But why unalias grep --color is working? I mean without using --?
    As it worked for alias even for unalias it is possible to give more than one name in one time (again the [...]).

    unalias: unalias [-a] name [name ...]

    I can give only my guess: a good programming habit is to write the reading and writing routines at the same time, below the same logic. So it has to be for the option parsing routines of alias and unalias.

    That this works you can see even from this command (from a shell opened for this purpose) that will not erase all your aliases:

    unalias whatever -a

Final remark

In the BUGS section of man bash among the few things reported you may read :-)

Aliases are confusing in some uses.


You must log in to answer this question.

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