pushd & popd: cd in a stack

terminalIf you use the terminal a lot, you spend a lot of time in directory navigation. I am not saying it’s slower than opening and clicking a file browser to navigate the filesystem but navigating on the terminal can be done in a smarter way. A utility that learns your most used locations and helps you navigate faster is autojump. Another handy way to navigate is the pushd and popd combination. pushd changes the directory and adds the current directory to the top of a stack. popd get you back to the directory at the top of the stack when you run it. Yes, it’s ‘cd -‘ with the ability to navigate further backwards than just the last visited location. You can replace pushd and popd with cd to save a lot of time in navigation. An example should help clear things:

tux:~$ pushd /usr/share/applications/
/usr/share/applications ~
tux:/usr/share/applications$ pushd /var/
/var /usr/share/applications ~
tux:/var$ pushd /tmp
/tmp /var /usr/share/applications ~
tux:/tmp$ popd
/var /usr/share/applications ~
tux:/var$ popd
/usr/share/applications ~
tux:/usr/share/applications$ popd

As you see the leftmost directory listed after running pushd or popd is the current directory at top of the stack.

To install on Ubuntu, run:

$ sudo apt-get install libfile-pushd-perl

Similar software

3 thoughts on “pushd & popd: cd in a stack”

Leave a Reply

Your email address will not be published. Required fields are marked *