CLI tip: Go back to the previous directory

By | November 29, 2008

While in Terminal, going back to the previous directory can be done with the classic cd ..
But there’s another way. make an alias of you choice for cd $OLDPWD, like this:

alias cdo=’cd $OLDPWD’

Now every time you’ll tipe cdo you’ll be taken to the previous directory you were in. This is very useful when you do a cd from, say, /home/username/Desktop to /usr/bin and want to quickly get back to you Desktop folder.

7 thoughts on “CLI tip: Go back to the previous directory

  1. Cameron

    Don’t worry about the alias—it’s easier than that!

    Try ‘cd -‘

    Similarly, cd called with no arguments at all will take back to your home directory.

    Reply
  2. Olx

    cd .. takes you to the parent directory.cd – takes you to the previous directory.

    Reply
  3. AmirWatad

    It’s still nice to know that there is an environment variable which stores the previous directory. It might be useful for other applications.
    Thanks for sharing.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *