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?

2

3 Answers 3

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:

1
  • 3
    Don't forget the obvious cd /home/user, too. ☺
    – JdeBP
    Nov 27, 2015 at 12:52
6

cd - returns to the previous directory.

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

-1

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

1
  • 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, 2015 at 15:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .