How do I search my command-line history for commands I used before?
Press Ctrl+R and type ssh
. Ctrl+R will start search from most recent command to old one (reverse-search). If you have more than one command which starts with ssh
, Press Ctrl+R again and again until you find the match.
Once you've found the match you can press Enter to execute the command or left / right cursor to just select the text of the command.
There is no default reverse option for Ctrl+R to invert the direction of the search but here you will find some suggestions about it.
If you just want to search your history, you can just use history | grep ssh
, substituting ssh for whatever you want to search.
I do a slight variation of the above, works well for me (if you're referring to your bash history
In my home folder I create a file named
.inputrc
Inside goes this
"\e[5~": history-search-backward
"\e[6~": history-search-forward
Note: the above doesn't seem to work anymore in 14.04 so this does the same thing -
"\e[A":history-search-backward
"\e[B":history-search-forward
Then typing however much of a previous command I wish & using the page up/page dn buttons searchs the history, always starting with page up