In modern bash shells, it is possible to hit CTRL+R, enter a keyword and do a reverse search for commands that were last used. This will search all previous commands with the keyword, regardless if the command started with this keyword or if that keyword were included at another position of this command. To continue the search, one would hit CTRL+R multiple times.
Full search for the keyword and single-direction CTRL+R search may be undesirable, so I am presenting another solution that will allow you to start entering a command, then use cursor up/down keys to cycle through commands in history. This will only search for commands that started exactly like you typed (it will not do a full search but complete from history).
Create/edit the file $HOME/.inputrc and add the following lines:
"\e[A": history-search-backward "\e[B": history-search-forward
Now re-login “or su -” for this change to go into effect. Start writing something and hit cursor up or down.
Action | Command |
---|---|
Clear line | CTRL+A + CTRL+K |
Clear before cursor | CTRL+U |
Clear after cursor | CTRL+K |
Clear word before cursor | Alt+W or CTRL+W |
Clear word after cursor | Alt+D |
Clear character after cursor | CTRL+D |
Recall deleted command | CTRL+Y (then Alt+Y) |
Go to beginning of line | CTRL+A |
Go to end of line | CTRL+E |
Go back one word | CTRL+left |
Go forward one word | CTRL+right |
Clear rest of terminal | CTRL+L |
Search command in history | CTRL+R |
End search at current entry | CTRL+J |
Cancel search & restore line | CTRL+G |
Next command from history | CTRL+N |
Previous command from history | CTRL+P |
Undo | CTRL+_ |