pushd, I hardly knew you

From a tech/geeky point of view, this is embarrassing enough that I probably shouldn’t mention it. There is hope, however, that some other soul will benefit from my pain.

If you use the *nix (or OS X) command line, you probably know about pushd. It and its companion popd let you push and pop (duh!) a stack of directories so that you can jump from place A to place B and then quickly jump back. Cool.

The embarrassing part is the way in which I was using pushd. I thought that I had to push the directory I wanted to come back to before I went there. So I would:

> pushd .
> cd /someplace
> ... do stuff ...
> popd

This works, but it (obviously) looks sort of, well, dumb. Somehow, when I learned about pushd, I never learned that it acts just like the change directory (cd) command. I.e., that the argument to pushd was the directory to which you want to move and that it saves your current directory automatically. Thus, the correct (more efficient) way to use pushd is:

> pushd /someplace
> ... do stuff ...
> popd

It only eight fewer keystrokes but it’s conceptually much cleaner. The morass of the story: use pushd but use it correctly. Alternately, keep reading the manual, you’ll probably still learn something!

This entry was posted in computers, humor, life, software. Bookmark the permalink.