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.

Assuming a Vistising sequence using cd: 1. directory C, 2, directory B, 3, directory A.

Now if we usually use cd -, it goes back to directory B

if we again use cd -, we come back to the directory A.

Is there any way we can go back to directory C?

Thanks!

share|improve this question

1 Answer 1

Try using pushd and popd instead of cd.

$ pushd ~/test/A
~/test/A ~/test
$ pushd ~/test/B
~/test/B ~/test/A ~/test
$ pushd ~/test/C
~/test/C ~/test/B ~/test/A ~/test
$ popd
~/test/B ~/test/A ~/test
$ popd
~/test/A ~/test

These commands maintain a stack of directories so that you can make your way back!

share|improve this answer
    
does this mean that we always need to use pushd instead of cd to change directories sothat the directory stack are recorded? –  Chenming Zhang May 16 at 3:36
    
Yes. You could alias cd='pushd >/dev/null' –  cpugeniusmv May 16 at 16:06

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.