Linux

How to change to the previous working directory on the command line on Linux

Written by Ian Carnaghan · 12 sec read >
  • Knowledge Base
  • Linux
  • How to change to the previous working directory on the command line on Linux

Type in the command below to go to your previous working directory

cd -

or

cd $OLDPWD

Points to remember

  • The “-” is short for previous working directory.
  • The previous working directory is defined by the shell variable $OLDPWD.
  • Everytime you use the cd command it sets the $OLDPWD environment variable.
  • Thus cd $OLDPWD is the same as cd –

Last Updated On April 07, 2018
Written by Ian Carnaghan
I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment. In my spare time I teach undergraduate classes in web development. Profile

Leave a Reply

avatar
  Subscribe  
Notify of