RTFM: cd

Okay maybe this is just me, but I have never been inclined to look up the man page for the cd command before today.

But when I did, I found two things of interest:

  • $OLDPWD : is set by the system when you use cd, it contains the path you last cded from
  • cd - : shorthand for cd $OLDPWD

It’s pretty simple but here’s a usage example on OSX:

~/Projects/config $ cd /Applications
/Applications $ rm -rf Firefox.app
/Applications $ cd -
/Users/acook/Projects/config
~/Projects/config $ git status
# On branch master
nothing to commit (working directory clean)
~/Projects/config $ cd -
/Applications $

So its really just an easy way to swap back and forth between directories, easier than using popd and pushd, which only let you swap once.

I’ve been meaning to write a script to handle directory history, hmm, maybe I will do that today while I am thinking about it..

⦂∀