dungphanxuan
dungphanxuan

Reputation: 615

mkdir throws 'unknown option' error

I have a problem with mkdir command. When I run mkdir -p "-AFolder", I am getting the following error:

mkdir: unknown option -- A

What's is causing the error?

Upvotes: 2

Views: 1545

Answers (3)

chepner
chepner

Reputation: 531055

In addition to the -- convention that mkdir supports, you can also prepend the directory name with ./.

mkdir ./-AFolder

Upvotes: 0

P....
P....

Reputation: 18361

mkdir -p  -- "-AFolder"

Use -- to tell the bash command that anything that follows is not a flag, its a part of the argument. From man bage:

-- A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and argu- ments. An argument of - is equivalent to --.

Upvotes: 2

damienfrancois
damienfrancois

Reputation: 59090

The mkdir command tries to interpret "-AFolder/" as an option as it begins with a -.

Use the -- dummy argument to tell explicitly that you are not providing an option :

mkdir -- -AFolder

From the Bash manpage:

Unless otherwise noted, each builtin command documented in this section as accepting options preceded by - accepts -- to signify the end of the options.

Upvotes: 4

Related Questions