Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given a history of commands:

1 pwd
2 mysql -u root -p
3 ps -ef | more
4 top
5 mysql -h -u root -p

When you press the Up arrow, you scroll through all those commands. I've read it somewhere before (and done it in my work PC) that you can set-up BASH such that when I first type p then press the Up arrow, it would only scroll through all commands in history that starts with "p" (pwd and ps -ef | more). When I type mysql then press Up, then it would only scroll through all commands starting with "mysql".

I'd like to set my laptop to use this, but I can't find the instructions again.

share|improve this question
up vote 9 down vote accepted

You can configure incremental searching in /etc/inputrc (for machine-wide changes), or ~/.inputrc (just for your user account).

Add these two lines:

"\e[A": history-search-backward
"\e[B": history-search-forward
share|improve this answer
/etc/inputrc requires root to edit and makes machine-wide changes, ~/.inputrc, is editable by ordinary users and makes changes just for that user. – James Polley Jan 8 '10 at 4:18
Forgot about that tidbit. Thanks. – John T Jan 8 '10 at 4:24
EXACTLY what I was looking for! Thanks! :D – Nikki Erwin Ramirez Jan 8 '10 at 10:54

Alternately, you could press ctrl+R to enter reverse-i-search mode. You can then start typing and it will find the first prior line that matches the string you type (ie, type m and it will jump back to mysql -h -u root -p; then type o and it will jump back to ps -ef | more as that's the first line with mo in.

You can hit ctrl+r again to search for the match before that (ie, ctrl+r,my,ctrl+r would take you to the second-last command starting with mysql)

You can read more about searching Readline's history search, commands for interacting with the history, and how you can modify the default keybindings and behavious in man bash (or online)

share|improve this answer
works in zsh as well – akira Jan 8 '10 at 7:45
Yup, I already use Ctrl+R. but sometimes, after I begin typing a long command, I suddenly need to check all similar commands I've used before. This happens when I type in a mysql command and have to scroll through commands in history with different parameters (database names, output file, input file, etc). – Nikki Erwin Ramirez Jan 8 '10 at 10:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.