7

This is a basic linux question I think, but I really want to know.

For example, currently I am in /usr/bin:

[x@localhost bin]$ pwd
/usr/bin
[x@localhost bin]$ cd /
[x@localhost /]$

Now I want to go back to previous path /usr/bin, how to do that quickly? I don't want to type cd /usr/bin again.

26

The command cd - will allow you to quickly return to the last directory.

You may also be interested in the pushd and popd commands which allow even more control over your directory navigation.

3

Depending on the shell you use, there's usually a variable with the previous working directory. In bash, I believe it's $OLDPWD

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.