4

I have directory name starting with --. How to enter it with cd? Basic escape charaters is not working

# cd --smol--/
    -bash: cd: --: invalid option
    cd: usage: cd [-L|[-P [-e]]] [dir]

# cd \-\-smol\-\-
    -bash: cd: --: invalid option
    cd: usage: cd [-L|[-P [-e]]] [dir]

# cd  '--smol--'
    -bash: cd: --: invalid option
    cd: usage: cd [-L|[-P [-e]]] [dir]

# cd '\-\-smol\-\-'
    -bash: cd: \-\-smol\-\-: No such file or directory

# help
  GNU bash, version 4.2.37(1)-release (i486-pc-linux-gnu)
petersmol
  • 61
  • 5

2 Answers2

6

You can use cd like this:

cd -- '--smol--'

OR:

cd -- --smol--

Anything after -- are not considered options for cd command.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    Another workaround is to reference the directory: `cd ./--smol--` or the absolute path from root. – sorpigal Jul 15 '15 at 11:20
4

You can prepend "./":

cd ./--smol--
Erik Bennett
  • 1,049
  • 6
  • 15