Linux: smarter file-system navigation on the command line
One of the most used commands on the terminal is the “cd” command because working from the command line most likely means that you need to go from your home directory to another directory, execute some commands and probably go back to your home directory, this is easy because “cd” without any directory returns you back to the home directory, but what happens if we have the following scenario:
- Goto /opt/app1/files/
- Goto ~/tmp
- Goto /opt/app1/files/
Well most likely you will do the following:
$ cd /opt/app1/files
$ cd ~/tmp
$ cd /opt/app1/files
But there is a cooler way, you can use a stack with the pushd and popd commands:
~$ cd /opt/app1/files
/opt/app1/files$ pushd ~/tmp
~/tmp$ popd
/opt/app1/files$
How it works?
pushd is like the cd command but with the additional step that before jumps to the new directory it stores the current to a stack.
popd is like the cd command but as a directory it takes the last inserted directory in the stack, note that the stack can be of any size, so you can backtrack all your current session pushd directories by entering popd many times.