In terminal, how can I define a key to go to the previous directory which I was in when changing directory with the
For example, I'm in
/opt/soft/bin and I
/etc/squid3 and I want to get back to the first directory.
The other answers are definitely complete in the direct answer sense.
Long story short, if you are moving into a directory with the ultimate intent of coming back to where you started, use
The major difference is easily shown by an example.
At this point, you have a directory stack that is
However, now you can now change directories multiple times and get back to
If you run
You can "define a key" for 'cd -' by editing your '~/.bashrc' file and including an alias for the command. For example you could add 'cdc' to make it 'cd -' which would provide you with a shorter way to get to the last directory by adding:
This way you would simply type 'cdc' and it would put you in your last working directory.