In addition to the history search via ctrl+r already mentioned, you can use the history entry number method you are already familiar with:
!<history entry number>
in the middle of other commands like
and even reference arguments from previous commands. For instance suppose in my history, entry 100 was:
I could do a host lookup on google by pulling the first argument from that history entry like so:
This works for the special reference to the previous command
as well. Of course for the numbered entries, you have to know their entry number by either typing history and looking, or piping to grep. If you want to pull from your history by matching the text, you can use the text from a previous command in the ! statement. For example using the fact that I have that ping google.com statement in my history, I can reference it like:
The thing to keep in mind with the search by text method is that it searches backwards and pulls the first match.