7 points · by sandreas · 7y ago · 5 comments
To achieve this, i used the "pushd" and "popd" command, which unfortunately seems not to be available on every POSIX platform. So, as an alternative, the pull request included:
cd -
which i never came across and which surprisingly (at least for me) did the same thing... Further research lead me to following information:"cd -" expands the "-" to $OLDPWD, which, as the name intends, points to the directory visited before. Using this variable results in a history size of 1, so you can only switch between the last and the current directory, but in most cases, that should be enough.
Then I immediately thought of a problem... how to change to a directory named "-"? Well, heres the answer:
cd ./-
Now that I know about it, I use it nearly every day.Have fun!
A similar one is
!!
For example
apt install python3
And you forgot sudo, whoops sudo !!
!! will be replaced by the last command you executed.Or
/etc/logs/apache2/error.log
Oh whoops, forgot cat/vim/less/tail/whatever vim !!
Etc