Introducing alternatives for easily navigating directories you’ve already visited. Prefer a reel over an article? here you go: instagram youtube
1. Going back to the previous directory
In standard shells - with cd is translated to $OLDPWD. So if you type cd - it will jump to the previous directory immediately!
Note that, this is different from .. which jumps to the parent directory.
2. Going to previous previous directory
There’s unfortunately no standard way to do this with plain cd. You need to use the commands pushd and popd. The pushd command pushes the directory to the directory stack and you cd into it. The popd command pops the stack and you cd into the popped directory. So pushd twice then popd twice will land you to your original directory.
One would want to create aliases as follows but I would recommend that look into the shell specific section if you’re fish or zsh user.
alias cd='pushd'alias cd-='popd'alias cd--='popd;popd'alias cd---='popd;popd;popd'3. Search through the history
Want to visit a directory that you’ve visited before but don’t remember or don’t want to type out the exact path?
Out of the box, you get reverse incremental search by pressing Ctrl+R.
This lets you search through your shell history for the commands you typed. This is an easy way to go to a directory in the history - though it’s a more generic solution - you can run any previous command you had run before.