It's common to rerun a command that you have used before. A less-commonly known fact is that your system keeps a track of all your previously-run commands. You can run the following command to get the list:

$ history

Searching for a command now becomes easy, just "grep" the output to find what you're looking for.

$ history | grep ssh
$ history | grep "npm install"

Try running the above commands, and you would get the list of your previous ssh sessions and the packages you've installed using npm.

To take this a step further, you can also press "ctrl + r" in your terminal to start a dynamic search through your history. You can now type out a subset of the command and you'll be shown the nearest matching command as an autocomplete suggestion.

🤓Try out iTerm2 (macOS Terminal Replacement) + Oh My ZSH! combination. This is the first thing that I ask my interns to install. It makes life so much easier!