Intelligent Console History Search

Everyone knows, or should know, that typing CTRL+R on the command line and typing something will perform a reverse search through your command history.

This system can be improved upon.

With the code shown below you can start typing on the command line then hit the up-arrow to match the last instance in yoru history of what you have’ve written. Pressing the up-arrow again will print the match after the first and so on.

The code to do this is as follows:

export HISTSIZE= 
export HISTCONTROL=erasedups
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind '"\e[C": forward-char'
bind '"\e[D": backward-char'

Simply copy and paste this into your ~/.bashrc file and then reload local environment:

source ~/.bashrc

You’re all set to give it a test.