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).
pushd and popd can be very useful. For example try
$ pushd somedir
and when you are done, just do
and you are back where you started.
The best part is you can do
$ pushd somedir $ pushd anotherdir $ pushd onemoredir
and then you can "step back" one at a time using popd.
cd - will take you back to the previous directory.
Also look into the
popd commands which can be used to basically save an ordered list of directories you were in and go back to them.
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