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?

link|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
feedback

2 Answers

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 ~]$ 
link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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