Search Bash history by first few characters (like MATLAB)

One convenient feature of the MATLAB interpreter is the ability to type in the first few characters of a previous command and press the "up" arrow to search for all previous commands that begin with those characters. Bash doesn't enable this behavior by default - you can use ctrl+r to search anywhere in a command, but not by the first few characters. If you want to add this functionality to Bash, add the following to your ~/.inputrc file (from this helpful post):

## Search backwards with the up arrow
## Search forwards with the down arrow

Now just type the first few characters of a command in your history, and press the up arrow to search backward or the down arrow to search forward.