yth yth - 11 months ago 41
Linux Question

Error with cd Command with "-=" in the Target Directory's Name

I came across an interesting phenomenon when trying to use the 'cd' command with some of my directories.

I have named a number of my directories "-= [name]" so that they will be sorted to the top when I sort by name on a Windows machine at work. At home, I use a Linux machine. I use a USB stick to carry files between the two machines. I find I could not get into my directories that have names in form of "-= [name]" using 'cd' command.

The tab auto-complete does 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 message:

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'm curious what's going on with the cd command. File managers are able to open up the directory with no problems.

Answer Source

Use cd -- or prefix ./ before your directory name.

cd -- file_path_to\\-\=\ directory_name


cd ./file_path_to\\-\=\ directory_name

Otherwise - is considered an option to cd command.