Error with cd command with "- =" in the target directory name

I ran into an interesting phenomenon while trying to use the "cd" command on some of my directories.

I named several of my directories "- = [name]" so that they are sorted by top when I sort by name on a Windows machine. I am using a Linux machine at home. I am using a USB stick to transfer files between two machines. I find that I cannot get into my directories that have names of the form "- = [name]" using the "cd" command.

Autocomplete tabs will recognize the directory and give the correct form. So the cd command would look something like this:

cd \-\=\ directory_name

      

However, I keep getting the following error:

bash: cd: -=: invalid option
cd: usage: cd [-L|[-P [-e]] [-@]] [dir].

      

Does anyone know me what's going on here?

I know I can just change the names of my directories. But I am curious what is going on with the cd command. File managers can open the directory with no problem.

+3


source to share


2 answers


Use cd --

or prefix ./

before your directory name.

cd -- file_path_to\\-\=\ directory_name

      

OR



cd ./file_path_to\\-\=\ directory_name

      

Otherwise, -

it is considered a command option cd

.

+2


source


Command line arguments start with -

. cd

It expects that -<option>

, and -=

this is not a valid option.

You will see this with almost any other line -X

.

$ cd -felkj
-bash: cd: -f: invalid option
cd: usage: cd [-L|-P] [dir]
$ cd -j
-bash: cd: -j: invalid option
cd: usage: cd [-L|-P] [dir]
$ cd -y
-bash: cd: -y: invalid option
cd: usage: cd [-L|-P] [dir]

      



You need to communicate cd

that you have finished with the arguments with --

:

$ pwd
/tmp/f
$ ls
-foo/
$ cd -foo/
-bash: cd: -f: invalid option
cd: usage: cd [-L|-P] [dir]
$ cd -- -foo/
$ pwd
/tmp/f/-foo

      

Alternatively, use any valid path prefix before the name (for example, ./-foo

or /tmp/f/-foo

).

0


source







All Articles