Linux

Categorized | cli

CLI tip: Go back to the previous directory

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.

Author Profile

T4L ;

Other posts by T4L

Author's web site



Are you satisfied with this blog?
Why not subscribe our RSS Feed? you will always get the latest post.


5 Comments

  1. 1

  2. 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.

    2
  3. Olx

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

    3
  4. FND

    Isn’t this the same as typing cd -?

    4

  5. 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.

    5

Leave A Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>