Some practical bash today.
In bash there is
cd -. Using these two buddies, we can jump between two directories very quick. I use them all the time.
More in the dark there is
dirs. Those I rarely had a usecase for. Until I started digging.
There is however a couple of them.
popd work on an internal stack for directories and allow to alter them and: to expand them.
Usually there is only one entry in them: the current
$ cd ~ $ dirs -v 0 ~
This single entry is constantly rewritten whenever you change the directory.
$ cd ~ $ dirs -v 0 ~ $ cd /mnt $ dirs -v 0 /mnt
pushd we can put other paths into that stack as well:
$ cd ~
$ pushd /mnt
$/mnt> dirs -v
/mnt got placed on the top of the stack without overwriting the exiting value
~. That one got pushed to the index level 1 instead. Also notice that the current path has changed from
/mnt. This is something
popd do. Use
pushd/popd -n <dir> if you do not want that.
With every change in the path, the index 0 is getting overwritten, while the index 1 in the stack keeps consistent.
This is something that can be used to quickly jump between multiple directorys. The index can be address like
cd ~1 to jump to
~. With only one or two entries in the stack, it’s not that big advantage over the use of
But with a couple of directories initially put in the stack, this can speed up directory navigation quite fast.
You empty the stack with
popd will also by default change to the directory you just popd.
popd are both bash builtins. Therefore the documentation points to the bash man page.