We have some folders where the names are starting with a "-". If I try to enter them with terminal, cd
interprets the "-" as an option. How could I manage this?
This should just work:
cd /path/to/-folderthatstartswithdash
EDIT:
According to this question, this works if you only want to input the name:
cd -- -folderthatstartswithdash
-
5The
--
method is the correct answer... it will work with most standard utilities that accept a filename as an argument and saves having to fully qualify the path. – Kaithar Mar 21 '17 at 23:58 -
-
3Why the restriction "if you only want to input the name"? If you need more arguments, just put them before the
--
. – Federico Poloni Mar 22 '17 at 7:57 -
@FedericoPoloni I'm just saying if you don't want the full path you can use this one. All other arguments should go before the --. – Tom Shen Mar 22 '17 at 10:26
cd ./-folder
usually works quite well here (and also with other commands)
-
One nice thing about this solution is that it works with any program or command, not just 'cd'; it does not depend on the command or program having any special behavior like "--" to turn change the interpretation of subsequent arguments. – Larry Gritz Mar 27 '17 at 18:51
Putting the name in quotes should work.
-
3Why would that work? How is the utility going to know the difference? Quoting is done by the shell, after all, the arguments array the utility receive will be exactly the same either way. I admit that I didn't try your solution, but from what little I know about shells, it seems pretty self-evident, that this cannot possibly work. – Jörg W Mittag Mar 21 '17 at 18:29
-
This should work on Windows IIRC, and is what I thought of first, but I can confirm that it doesn't work on mac. – Cullub Mar 21 '17 at 19:49
-
2If it works on Windows that's only because Windows' command line model is utterly ridiculous and inconsistent. Or just because Windows commands aren't treating
-
as an option character. But there's no way quoting should be able to change this behavior. – R.. GitHub STOP HELPING ICE Mar 21 '17 at 22:03
cd '-my-directory'
? – OldBunny2800 Mar 22 '17 at 0:09