up vote 0 down vote favorite
share [g+] share [fb]

I know I can pushd / popd if I want to save the current location before chdir into another directory. In bash I can go back to the directory before the last chdir by:

$ chdir /somedir
$ chdir -

I'm wondering if I can go back for several steps (chdir ---- maybe??), just using chdir rather than pushd / popd, in bash is that possible?

link|improve this question

feedback

2 Answers

Did you know that pushd saves directories on a stack, so it can have multiple directories saved?

You can skip around using a command such as:

pushd +3; popd
link|improve this answer
1  
You can even use alias cd=pushd, to avoid having to type the extra characters in pushd. – Chris Johnsen Dec 20 '09 at 6:15
Thanks, but pushd prints the annoying stack contents, and, BTW won't it be blown up if pushd too many times? – Xie Jilei Jul 10 '10 at 8:29
feedback
up vote -1 down vote accepted

No, it's impossible.

link|improve this answer
You can always write a shell function wrapper around chdir that checks if the argument is multiple dashes and then calls popd, while dumping the stack contents to /dev/null. – eldering Oct 28 '11 at 13:07
feedback

Your Answer

 
or
required, but never shown

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