Skip to content

Instantly share code, notes, and snippets.

@matthewrudy
Created June 28, 2011 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewrudy/1050592 to your computer and use it in GitHub Desktop.
Save matthewrudy/1050592 to your computer and use it in GitHub Desktop.
Trying to cd to a directory with a hypen
# /var/folders/*whatever*/ has a folder named '-Tmp-'
$ ls
-Caches-/ -Tmp-/
# lets try and CD there
$ cd -Tmp-
-bash: cd: -T: invalid option
cd: usage: cd [-L|-P] [dir]
# or maybe make sure its a directory
$ cd -Tmp-/
-bash: cd: -T: invalid option
cd: usage: cd [-L|-P] [dir]
# try and escape the first -
$ cd \-Tmp-
-bash: cd: -T: invalid option
cd: usage: cd [-L|-P] [dir]
# quote it
$ cd '-Tmp-'
-bash: cd: -T: invalid option
cd: usage: cd [-L|-P] [dir]
# double quote it
$ cd "-Tmp-"
-bash: cd: -T: invalid option
cd: usage: cd [-L|-P] [dir]
# escape it in the quotes
$ cd '\-Tmp-'
-bash: cd: \-Tmp-: No such file or directory
# escape it in the double quotes
$ cd "\-Tmp-"
-bash: cd: \-Tmp-: No such file or directory
# try a "./" hack
$ cd ./-Tmp-/
$ echo "WHOOP"
WHOOP
@thermistor
Copy link

the unix way is to put -- after all your switches to indicate that anything afterwards is not a switch

cd -- -Tmp-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment