I'd like to be able to type in terminal commands of forward/back especially if I went from a directory with a super-long name to home (and want to return back to the directory with the super-long name).
As well as
cd - and
popd which others have mentioned, there is also
cd $OLDPWD. usually
cd $OL<TAB> is enough, auto-completion at work.
dirs builtin can really help out, for example:
dirs -v prints the directory stack with one entry per line, prefixed with its position number in the stack. try
help dirs for more.
Note that if you want change to a directory named
-, should you have one, the above feature poses a problem. you will need to do
cd ./-. better still, don't give your directories such names.
There is a script that,by typing
cd --, allows one to switch to one of the ten last visited directories whilst being in a particular Bash shell. Here is an example of its use:
lotzmana@safe$ cd work lotzmana@safe$ cd scripts lotzmana@safe$ pwd /home/petarma/work/scripts lotzmana@safe$ cd -- 0 ~/work/scripts 1 ~/work 2 ~ lotzmana@safe$ cd -2 lotzmana@safe$ pwd /home/petarma