Question

Trying to mkdir with a leading hyphen in the name.

 mkdir -foo-
 mkdir '-foo-'
 mkdir `-foo-`
 mkdir `echo '-foo-'`

None of these work. Is there any way to do this?

Was it helpful?

Solution

Try using -- to disable further option parsing:

mkdir -- -foo

OTHER TIPS

How about

$ mkdir ./-dir

in order to specify the directory with the current dir prefixed. The same 'trick' can be used with all other command line utils (e.g. rmdir, rm etc.).

I perhaps wouldn't create such a directory, though, unless it's really necessary. It's a little counter-intuitive and may cause similar confusion for others in the future.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top