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.

Edit:

"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?

Regards

share|improve this question
1  
As noted below, you can do so using "pushd" and "popd". –  blueyed Mar 5 '10 at 3:02
4  
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 106 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.

share|improve this answer
7  
also pushd and popd might be useful –  lorenzog Feb 25 '10 at 8:55
2  
@lorenzog : lydonchandra, in his question, said "without using pushd/popd" –  Snark Feb 25 '10 at 9:19
1  
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
    
cd -- seems to go back 2 directories –  ogc-nick May 21 at 17:07
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.

share|improve this answer
11  
.. is not the previous directory, it's just the parent directory. –  Oliver Salzburg Dec 10 '12 at 10:28
add comment

Your Answer

 
discard

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

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