re: BASH tricks: The dir stack. VIEW POST

FULL DISCUSSION
 

A lesser-known feature of most shells (including bash) is cd - which returns you to the previous directory you were in, without affecting (or relying on) the stack. This is useful if you cd somewhere and then realize you need to go back to the previous one. It's basically an undo for cd!

And of course you can combine this with pushd and do pushd -.

Some other tools make use of this nomenclature as well; for example, git checkout uses - as a quick alias to the previous branch you were in.

 

And of course you can combine this with pushd and do pushd -.

Cool! I knew about cd - but I never thought to try pushd -. Thanks for sharing @fluffy , TIL.

code of conduct - report abuse