How to Go Back To Previous Directory and Home Directory in Linux Shell or Putty?

We have been using Putty to access Linux servers for quite some time, and we have shared several Linux Tips in the past, here is another tip that should be useful for many users.

If you used cd to change the directory in Linux you can easily go back to the previous directory by using a command. For example you were in /usr/keith/my/inner/directory/which/is/so/deep and you use the command cd /var/www you can go back to the previous directory without having to type in the entire directory path by using the command cd .

If you want to go back to your default home directory from any directory, type in either cd ~or simply cd, this should take you to your home directory.

Bonus Tips: If you want to find the exact directory you are in type the command pwd". If you want to navigate to a sub-folder in your home directory you can use the ~ sign to replace the path to your home directory, so cd /home/keith/dir1 and cd ~/dir1 should take you to the same directory.

You can also use auto-completion for file and directory names by using the tab key, if there are more than one files or folders matching the text you typed in, you will be shown a list of entries to choose from.

Published by

Keith Dsouza

I am the editor-in-chief and owner of Techie Buzz. I love coding and have contributed to several open source projects in the past. You can know more about me and my projects by visiting my Personal Website.I am also a social networking enthusiast and can be found active on twitter, you can follow Keith on twitter @keithdsouza. You can click on my name to visit my Google+ profile.

  • Geeves

    Don’t forget about “!$” which gives you the last argument. so:
    mkdir ReallyLondDirectoryName
    cd !$

    Is the same as doing:
    mkdir ReallyLondDirectoryName
    cd ReallyLondDirectoryName

  • I think the command you’re looking for is “cd -“.

  • Thanks Dustin

  • Patrick Mitchell

    The command for returning to the last directory is actually cd -, not cd . (cd dash, not cd dot). “cd .” brings you to the current directory, which is very rarely useful.