History Expansion
ok so bash remembers everything you type (check ~/.bash_history) and you can pull stuff back really fast.
the ones I actually use
!! — reruns the last command. everyone knows the sudo trick:
apt update
# nope, permission denied
sudo !!!$ — last argument from whatever you just ran. I use this ALL the time:
mkdir /tmp/whatever
cd !$saves so much retyping. there’s also !^ for the first arg and !* for all of them but honestly I mostly just use !$.
finding old stuff
!ssh runs your last command that started with ssh. kinda dangerous though — you might not remember exactly what that command was. safer version: slap :p on the end to preview it:
!ssh:p
# shows what it WOULD run, without actually running itCtrl+R is honestly better for searching history though, see bash-keyboard-shortcuts.
the typo fixer
this one’s underrated:
cat /etc/ngnix/nginx.conf
^ngnix^nginxboom, fixed. only does the first occurrence though.
see also: bash-keyboard-shortcuts, bash-brace-expansion
gnu manual on this stuff if you want the deep dive