How can I make pressing up/down on bash bring up the last command that started with the prefix I already entered?
$ ls foo $ echo hello $ ls <UP_ARROW>
Clicking UP after entering ls should bring up "ls foo" and not "echo hello"
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
A few possibilities:
history-search-backward/forward commands. I believe this is closest to what you want:
bind '"\e[A":history-search-backward' bind '"\e[B":history-search-forward'
Use the history i-search. This is probably bound to
^R. On an empty line,
^Rls<space> will get you back to
ls foo, then
^R again will take you to the last
ls command (or other command with
ls somewhere in the line) before
ls foo, etc...
bind SPACE:magic-space. Then type (on an empty line)
!ls<space>, and readline will perform history substitution automatically, leaving you with