Command-line completion from command history
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
To expand on what Gilles said, I have the following in my .inputrc
to bind the up/down arrow key to history-search-backward
and history-search-forward
:
# Key bindings, up/down arrow searches through history
"\e[A": history-search-backward
"\e[B": history-search-forward
"\eOA": history-search-backward
"\eOB": history-search-forward
Just type something (optional), then press up/down arrow key to search through history for commands that begin with what you typed.
To do this in .bashrc
rather than .inputrc
, you can use:
bind '"\e[A": history-search-backward'
You could also press the PAGEUP
button to auto-complete a command. It basically searches the bash_history
file.