Create Directory with Hypen

2018-05-02 ·

Use mkdir with -- to create a directory with a hyphen in the name. This disables further option parsing.

mkdir -- -my-dir

Put additional options always before --

mkdir -p -- -my-dir/foo

This is a convention that is part of the POSIX standard. The argument -- is a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.

Alternatively, use the current directory prefix

mkdir ./-my-dir

This also applies to other commands such as cd:

cd -- -my-dir

or rm

rm -r -- -my-dir
Copyright © 2019 All rights reserved.
Powered by Kulfon.