3

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?

  • cd ~ will go in home – josifoski Nov 27 '15 at 12:38
11

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:

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

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.

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.