Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create an alias for cd - which should be just a dash (-). I tried without success:

alias -='cd -'     # bash: alias: -=: Invalid option
alias \-='cd -'    # bash: alias: -=: Invalid option
alias '-'='cd -'   # bash: alias: -=: Invalid option
alias '\-'='cd -'  # bash: alias: `\-': Invalid alias name.

The former three are the same (only different input, but bash turns all of them into the same command alias with a single argument -=cd -), so it's no surprise the error message is the same. I'd guess that if the argument starts with a dash, it's parsed as a flag rather than the alias name.

Is it even possible to use - as an alias name?

share|improve this question
Never knew about cd - – Marco Ceppi Jun 4 '12 at 0:01
@MarcoCeppi Me neither, until today. Checkout for more nice tricks! – leemes Jun 4 '12 at 0:45
up vote 18 down vote accepted

With most commands, you can pass -- as an argument, and all subsequent arguments are treated as operands and not options, even if they begin with a dash. The alias builtin in bash recognizes --.

alias -- -='cd -'
share|improve this answer
Hah! Didn't know this. Cool, thanks! :) – leemes Jun 3 '12 at 19:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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