4 ms·
If you like this, you'll also like pushd/popd. Example: $ cd ~/src/app/foo/bar/baz $ pushd /etc/qux/quux/quuz/corge/grault/garply/waldo $ popd $ pwd /home/
by sowbug 7y ago
If you like this, you'll also like pushd/popd. Example:
$ cd ~/src/app/foo/bar/baz
$ pushd /etc/qux/quux/quuz/corge/grault/garply/waldo
$ popd
$ pwd
/home/you/src/app/foo/bar/baz
It's a stack of directories. You pushd the current directory on to the stack and cd to a new directory all in a single command, then you popd back to the previous directory (i.e., the one on the top of the stack). It's useful if you're jumping all over the filesystem to do work, or if someone interrupts you and you want to cd somewhere to show them the contents of a file without losing your own context.
- abathur 7y agoIt's not as robust as pushd/popd, and it may vary from shell to shell, but at least in bash you can also use "cd -" to change to the previous directory.
- jcelerier 7y agopro tip : you can also do the same with git : "git checkout -" will bring you to the previous commit you were on
- tryptophan 7y agoOr you could try autojump. It tracks where you have cd and then you can jump to locations from past history using fuzzy matching. so if you cd to /usr/home/me/tacos once, from then on you can just > j taco and it will cd to that directory. Saves so much time! Instead of typing out /etc/nginx you can just type "j e ng" and it will jump there.