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.

4 thoughts on “How to Go Back To Previous Directory and Home Directory in Linux Shell or Putty?”

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

    Is the same as doing:
    mkdir ReallyLondDirectoryName
    cd ReallyLondDirectoryName

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

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>