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.

Is there a way to go back to previous directory we were in using bash,tcsh without using pushd/popd ? I'd like to type something like "back" and got returned to the previous directory I was in.


"cd -" works, but only for current and previous directories. Is there anyway I can go back to the previous previous previous directory like how you can go back in the web browser?


As noted below, you can do so using "pushd" and "popd". –  blueyed Mar 5 '10 at 3:02
Just a side note "cd --" goes to the user default direcotry (/home/username) –  realdreams Apr 8 '12 at 22:49
add comment

2 Answers

up vote 94 down vote accepted

cd - (goes back to previous directory)

If you want to be able to go to the other previous directories, this is not possible out of the box. But check this script and instructions:

History of visited directories in BASH

The cd command works as usual. The new feature is the history of the last 10 directories and the cd command expanded to display and access it. cd -- (or simply pressing ctrl+w) shows the history. In front of every directory name you see a number. cd -num with the number you want jumps to the corresponding directory from the history.

also pushd and popd might be useful –  lorenzog Feb 25 '10 at 8:55
@lorenzog : lydonchandra, in his question, said "without using pushd/popd" –  Snark Feb 25 '10 at 9:19
whops. missed it. thanks –  lorenzog Feb 25 '10 at 9:50
Thanks for this, just what i was looking for! :) –  Richards Mar 6 '11 at 16:55
add comment

I think cd .. might help. If you do a ls -a in any directory you would see that there are two entries: one named "." and another named ".."; the single dot is reference to the directory you are already in, while the double is the previous directory in the path.

.. is not the previous directory, it's just the parent directory. –  Oliver Salzburg Dec 10 '12 at 10:28
add comment

This site is currently not accepting new answers.

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