Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

The command

cd -

will change the pwd to the last directory.

Is there a way to know which directory it is, so that I'll know where I am CD'ing to?

share|improve this question

migrated from stackoverflow.com Dec 19 '09 at 2:46

This question came from our site for professional and enthusiast programmers.

3 Answers 3

Yes, it is $OLDPWD.

~$ cd src/
~/src$ cd ..
~$ echo $OLDPWD
share|improve this answer
Thanks Dirk for the quick solution. –  Abhijit Dec 18 '09 at 13:04
Always a pleasure :) –  Dirk Eddelbuettel Dec 18 '09 at 13:18
"echo ~-" will output the same information –  njd Feb 19 '10 at 15:23

The previous directory is saved in $OLDPWD

share|improve this answer

You can also use ~- (anywhere you can use tilde expansion) instead of $OLDPWD:

# Copy a file from the previous working directory.
cp ~-/file1 .

There is also ~+ for $PWD, which is useful for commands which require an absolute directory:

./configure --prefix ~+/root

Note that things like --prefix=~+/root won't work due to the rules of tilde expansion; use --prefix="$PWD/root" instead.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.