[WayBack] bash – Search for a previous command with the prefix I just typed – Unix & Linux Stack Exchange answered by [WayBack] John1024:
What you are looking for is
Ctrl-R
.Type
Ctrl-R
and then type part of the command you want. Bash will display the first matching command. Keep typingCtrlR
and bash will cycle through previous matching commands.To search backwards in the history, type
Ctrl-S
instead. (IfCtrl-S
doesn’t work that way for you, that likely means that you need to disable XON/XOFF flow control: to do that, runstty -ixon
.)This is documented under “Searching” in
man bash
.
Comment by [WayBack] HongboZhu:
Ctrl-Q
to quit the frozen state, if you already hitCtrl-S
without turning off flow control first and got your terminal frozen.
A far more elaborate answer with many other tips is from [WayBack] Peter Cordes: