Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change directory in unix shell (special characters)

Tags:

bash

unix

cd

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)
like image 528
petersmol Avatar asked Oct 24 '25 09:10

petersmol


1 Answers

You can use cd like this:

cd -- '--smol--'

OR:

cd -- --smol--

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

like image 67
anubhava Avatar answered Oct 26 '25 00:10

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!