Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question already has an answer here:

In Bash, how could I create a directory named -p?

mkdir -p failed.
mkdir "-p" failed.
mkdir "\-p" failed.
mkdir \-p failed.

share|improve this question

marked as duplicate by Daniel Beck Apr 7 at 20:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
Note that all of these are attempting to escape the parameter for bash. Since it's the same escaped as not escaped, all of these except the third will just send the string "-p" to mkdir, which will parse it as an option. The option parsing isn't done in bash, so any way around this (described in the answers below) is a feature of mkdir (or rather, a lack of bug). –  Score_Under Apr 7 at 11:40
11  
Gotta ask why you'd want such a directory. It would be a PITA to use. –  Daniel R Hicks Apr 7 at 11:44
3  
@DanielRHicks: I created this folder by mistake, but do not know how to delete it. –  Jichao Apr 7 at 14:19
4  
Shouldn't, then, the question be "How to delete a directory named '-p' under Linux with Bash"? –  chepner Apr 7 at 16:15
    
@chepner: Because they are same problems actually. I tried to delete the directory with rmdir but failed with same errors. –  Jichao Apr 7 at 16:41

2 Answers 2

up vote 40 down vote accepted

Most utilities (all POSIX compliant ones except for test and echo) support an "end of options" option --, so you could run:

mkdir -- -p

This is especially useful when renaming or removing files that could potentially start with a dash. In scripts you should always use

mv -- "$filename"

instead of a plain mv "$filename" or, even worse, an unquoted filename.

share|improve this answer
3  
Awesome. This is really good to know –  Bruno9779 Apr 7 at 16:53

mkdir ./-p

Keep in mind that most other programs would need to use the same "trick".

share|improve this answer

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