4

First i did pwd, it says:

/home/user

I changed my directory using :

cd /Italic/Food/Places

Now, I want to go back to original directory: /home/user. How can I do this?

muru
  • 197,895
  • 55
  • 485
  • 740

3 Answers3

13

To cd to the previous directory, you can use one of the following commands in bash:

cd -
cd "$OLDPWD"

To cd to your home directory, use one of:

cd
cd ~
cd "$HOME"

If you want to undo multiple cds, cd can't help you. You'll have to use the pushd and popd commands. Instead of cd foo/bar, do

pushd foo/bar

Then you can use the popd command to undo as many times as you have used pushd.

Example:

/tmp/lightdm-1.10.5 $ pushd ~
~ /tmp/lightdm-1.10.5
~ $ pushd devel
~/devel ~ /tmp/lightdm-1.10.5
~/devel $ popd
~ /tmp/lightdm-1.10.5
~ $ popd
/tmp/lightdm-1.10.5
/tmp/lightdm-1.10.5 $

Also see:

muru
  • 197,895
  • 55
  • 485
  • 740
6

cd - returns to the previous directory.

If you want to go to home dir specifically, use cd, cd $HOME, or cd ~.

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
-1

cd ~ will work. ~ is basically a shortcut for /home/user. If cd ~ takes you to the home folder, then use cd ~/user instead.

  • The answer may work for the particular case (if the current user is called user and if that’s indeed her home directory) but not for any other directory. – Chriki Nov 28 '15 at 15:59