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.

I was wondering if there was a way to navigate back to the previous folder after a 'cd'.

e.g.

~/ cd /home/
~/ cd /usr/local/
~/ want should I write here to return to the home dir (not 'cd /home' ^^)

Any suggestions?

share|improve this question
    
Any particular shell? –  Ignacio Vazquez-Abrams Sep 10 '11 at 8:19
    
I am using the standard gnome-terminal that comes with ubuntu 11.04 (not Unity) –  bliof Sep 10 '11 at 8:24
    
gnome-terminal is not a shell. –  Ignacio Vazquez-Abrams Sep 10 '11 at 8:24
    
I didn't say that –  bliof Sep 10 '11 at 8:25

2 Answers 2

up vote 2 down vote accepted

If you're using bash or some similar shell you can use cd - to return to the previous working directory.

[ignacio@localhost ~]$ cd bin/
[ignacio@localhost bin]$ cd -
/home/ignacio
[ignacio@localhost ~]$ 
share|improve this answer

The pushd/popd utilities keep a stack of the directories that you have visited.

[arcege]:~/Documents> pushd /usr/local
/usr/local ~/Documents
[arcege]:/usr/local> pushd /tmp
/tmp /usr/local ~/Documents
[arcege]:/tmp> dirs
/tmp /usr/local ~/Documents
[arcege]:/tmp> popd
/usr/local ~/Documents
[arcege]:/usr/local> popd
~/Documents
[arcege]:~/Documents>

The downside is that you need to remember to use pushd instead of cd.

share|improve this answer

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.