I wanted to welcome in the new year by showing some terminal features I end up frequently demonstrating to my peers.
Bang Commands
You can look up your terminal history by time:
history
You can repeat any entry by typing it’s entry number like this:
!10
You can also repeat the last command with:
!!
Which is particularly useful when you forget to use sudo:
sudo !!
You can fetch by regex, e.g. last command that starts with npm:
!npm
You can fetch parts of the previous statement like the last word:
!$
or the first:
!%
you can substitute part of a previous command you’re grabbing:
!!:s/foo/bar
You can also just print the command before using it:
!!:p
Reusing a terminal
You can pause a job with ctrl + z. You can then have it run in the background with bg or bring it back to the foreground and resume it with fg. You can check all your paused jobs with jobs and manipulate them directly like:
fg %1 or kill %1
Alternatively you can use something like screen or tmux to create virtual shells inside of your shell. This can be useful when you want manage a long job and still be able to switch locations/computers without interrupting your session.