Bash – Command-Line Completion from Command History

autocompletebashcommand history

So, I've looked at history and at Ctrl+R, but they are not what I thought I knew.
Is there a way that I can type in the beginning of a command, and cycle through the matches in my history with some bash shortcut?

# mysq(some shortcut key)

Gives me:

# mysqldump  --add-drop-table -e -q -n -C -u 
(some shortcut key)
#  mysql -u ben.dauphinee -p

Best Answer

Pressing Ctrl+R will open the reverse history search. Now start typing your command, this will give the first match. By pressing Ctrl+R again (and again) you can cycle through the history.

mysq(Ctrl+R)

Would give:

mysqldump  --add-drop-table -e -q -n -C -u 

Ctrl+R again:

mysql -u ben.dauphinee -p