Ever get in a Linux directory and realize that you like this directory, but you need to take a quick little fling in a different one? Your current directory can’t give you what you need at that moment, but you know you want to come right back to it when you are done.
Well, throw directory commitment out the door with Linux’s built-in tools, pushd and popd.
Lets say you are in directory x, but you need to do a few things in directory y in order to then complete your tasks in directory x. Simply, type in “pushd y”. Now you are in directory y. Stay a little while and do what you needed to do. Have your fun, but when it is time to get out and you want to be back with x, simply type “popd”. You’re back with x in no time.
With these tools you are simply pushing a directory onto a stack of directories. When you call the popd command, you just pop the current directory off the stack and return to the previous one. Easy!
Note: It is hazardous to your help to implement these tools in your own personal life – I recommend you only use these with directories – not people.
How does this differ from,
pwd
/somedir1
cd /somedir2
do work
cd –
pwd
/somedir1
@Micheal – I beleive “cd -” will take you back to the previous location only, whereas pushd queues up a series of locations and popd takes you back to those locations. You can have a longer chain of directories to go back to with pushd/popd.