In Bash, how could I create a directory named -p?
mkdir -p failed.
mkdir "-p" failed.
mkdir "\-p" failed.
mkdir \-p failed.
In Bash, how could I create a directory named -p?
mkdir -p failed.
mkdir "-p" failed.
mkdir "\-p" failed.
mkdir \-p failed.
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.
mkdir ./-p
Keep in mind that most other programs would need to use the same "trick".