Making History with Bash

This is a nifty little trick for making Bash a little more intuitive (for my taste). Usually, when you press the up key, Bash will bring back the last command you typed. This is cool, but what bothers me is that sometimes I start typing a command and then remember I executed it before. So I press the up key and… Bash shows me the last command, disregarding what I typed. What I want it to do is search history for things with the prefix I entered.

Here’s what you do to achieve this. In your inputrc file (~/.inputrc for personal configuration, /etc/inputrc file for global configuration), add the following lines:

"\C-[OA": history-search-backward
"\C-[[A": history-search-backward
"\C-[OB": history-search-forward
"\C-[[B": history-search-forward

The weird symbols at the start of each line represent up/down arrow keys in keypad/ANSI modes. I wish Unix configurations would use proper readable symbols, but a man can only dream.

Discuss this post at the comment section below.
Follow me on Twitter , Facebook or Google+

Similar Posts