What does 'cd -' stand for?

cd - brings you back to the last directory.

$ cd ~/Desktop
$ pwd
/Users/daknok/Desktop
$ cd /
$ pwd
/
$ cd -
$ pwd
/Users/daknok/Desktop

cd - returns to the previous directory you were in.

Say I'm in /usr/ and I type cd /var/local/someplace/else

Then I use cd - I'll return to /usr


cd - returns to the directory you were previously.

For instance:

marcelo@marcelo:~$ cd /opt
marcelo@marcelo:/opt$ cd /usr/bin
marcelo@marcelo:/usr/bin$ cd -
/opt
marcelo@marcelo:/opt$ 

I was in /opt, changed to /usr/bin, and then went back to /opt with cd -


If a single dash is specified as the argument, it will be replaced by the value of OLDPWD.

The OLDPWD is set by cd command and it is the previous working directory.

Tags:

Linux

Shell

Bash