4 ms·
The `cdto` functionality (and then some) already exists in many shells, even the Windows shell. `pushd` switches directories and maintains a stack of visited d
by rcfox 16y ago
The `cdto` functionality (and then some) already exists in many shells, even the Windows shell.
`pushd` switches directories and maintains a stack of visited directories. `popd` pops the previous directory off the stack and then switches to it.
In zsh, it seems that `cd` is an alias for `pushd`. You can `cd` to a directory, then `popd` to go back.
In Windows, `pushd` seems to the easiest/only way to navigate to network directories on the command-line.
- koenigdavidmj 16y agoYou can also say `cd -` on Bourne shells to go back to the previously visited directory. If you move from A to B in this manner and then run it again, then you will go back to A. Also, `alias cd=pushd` to get that same zsh functionality in other Bourne shells.
- yason 16y agoI often find this idiomatic as well, both in scripts and on the command line: dostuff ( cd $directory && otherstuff ) morestuff