Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

This chapter is from the book

This chapter is from the book

Change to Your Previous Directory

cd -

Another interesting possibility is cd -, which takes you back to your previous directory and then runs the pwd command for you, printing your new (or is it old?) location. It’s the shell equivalent of the Back button in a GUI file navigator window. You can see it in action in this example:

$ pwd
/home/scott
$ cd music/new
$ pwd
/home/scott/music/new
$ cd -
/home/scott

Using cd - can be useful when you want to jump into a directory, perform some action there, and then jump back to your original directory. The additional printing to the screen of the information provided by pwd is just icing on the cake to make sure you’re where you want to be.

  • + Share This
  • 🔖 Save To Your Account