Search bash history for already typed command

The answer is in one of the "Related" questions listed automatically by stackexchange in the right-hand column. To experiment type

bind '"\e[A": history-search-backward'

then type your partial command and use up-arrow key (which should generate escape [ A) to search for this partial input in your history. See the full answer for more.


If you start typing a command and then, after typing some of it, remember to do a history search, you just need to:

  • CTRL+A
  • CTRL+R
  • CTRL+Y
  • CTRL+R ... (keep searching or)
  • CTRL+S ... (search in the other direction*)

Note: CTRL+S will suspend your terminal unless you explicitly revoked this behavior with

[[ $- == *i* ]] && stty -ixon

in your .bashrc


Edited: a shortcut can be seen here in this somewhat duplicated question https://superuser.com/questions/384051/is-there-a-way-of-using-ctrl-r-after-typing-part-of-command-in-bash/1271740#1271740