Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

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'm trying to make a folder called -. I know it's a silly name, it's named so to mirror something else.

mkdir -
> -
cd -

This makes it go up a folder or exit the symlink context depending on where I am. I found that cd - means go to previous location, but can't escape it. cd \- does not work.

Any way around this?

share|improve this question
up vote 9 down vote accepted

You can use either relative or absolute paths to prevent the - from standing alone and confusing bash's build in command cd:

mkdir ./-
cd ./-
share|improve this answer
Nice. I realized after I posted I could go up a level and navigate back down two levels but your answer is better. – SimplGy Feb 19 '14 at 21:23

Opposite to ~, which gets evaluated by bash, - is an argument to cd. Have a look at the man pages (well, for current systems both are in man bash as cd is a builtin):

   cd [-L|[-P [-e]]] [dir]
          Change the current directory to dir. [...]  An argument of - is equivalent
          to $OLDPWD. [...]

And the paragraph on tilde expansion (simplified to the most common meaning):

Tilde Expansion
   If  a  word begins with an unquoted tilde character (`~'), [...] the tilde-prefix 
   is replaced with the home  directory associated with the specified login name.

~ will be replaced by bash before passing the argument to the actual command. Thus, escaping it somehow (for example using '~' or \~) will work. - on the other hand will be passed to the command. Escaping has no use: bash will not evaluate it anyway, but it will get passed unescaped as single string to cd, which will subsequently open $OLDPWD.

A more esoteric alternative to Patrix' more reasonable way to open --folders would be to set $OLDPATH to -:

OLDPATH=- cd -
share|improve this answer
I like the esoteric alternative :-) – patrix Feb 20 '14 at 19:23

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.