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.