pushd

In the terminal, if you find yourself needing to move back and forth between two directories and don’t want to type in the complete path name constantly, you can either set up aliases of the cd command to the directory or you can use pushd. Let’s say you are in your Sites folder in your home directory which you can get to easily by typing:
cd ~/Sites.
Then you want to go to /Library/Webserver/CGI-Executables/.
Instead of typing:
cd /Library/Webserver/CGI-Execuatables
type:
pushd /Library/Webserver/CGI-Executables.
This creates a directory stack. When you have two directories in the stack, you can then just type in pushd without arguments and you will go back and forth between directories. Actually, you can add even more to the directory stack by doing a pushd. Then you would have to type in pushd +2 or whatever the number of the directory you want to go to. The terminal will print the stack below your command to let you know what is in your stack. The directory on the left is the one you are in and the stack goes down as you read to the right. You can remove directories by doing a popd. popd will pop off whatever directory is on the top of the stack. So make sure you do a pushd to the directory you want to pop before you do it. Of course you can type ‘pwd’ at any time to verify which directory you are in if you get confused.

Comments are closed.