Like `cd` in a directory named` -`?

Here is an example. I am creating a directory called - and I can not cd into it. The cd - returns me to the previous directory. And I'm a little surprised that the cd "-" works the same way. I can enter this directory using the full path ~/- , but is there any other way?

 user@server:~$ cd /tmp user@server:/tmp$ cd user@server:~$ mkdir - user@server:~$ cd - /tmp user@server:/tmp$ cd user@server:~$ cd "-" /tmp user@server:/tmp$ cd ~/- user@server:~/-$ 
+8
bash cd
source share
3 answers

use

 cd ./- 

if you are in the directory above.

+20
source share

or like this:

 cd -- -/ 

Adding / at the end of the file name ensures that the file is treated as a directory.

+7
source share

cd -- ./- should do the trick :)

It processes everything after -- as if not commands.

+4
source share

All Articles