Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question

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 '14 at 3:36
Yes. You could alias cd='pushd >/dev/null' – cpugeniusmv May 16 '14 at 16:06

Your Answer


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.