Supercharge Your Command Line's History Search With Four Lines Of Code

Mac/Linux: Pressing the up and down arrow lets you step through your history in the command line, but sometimes it can take a while to get your way to the command you want. Jude Robinson, posting on Coder Wall, shares four lines of code that make your search much faster.

With four lines, you'll be able to type the beginning of the command (e.g. "cd") and press the up arrow to see the most recent command containing the text you typed (e.g "cd ~/Library"). This makes it much easier to find what you're looking for. To make this happen, create a text file called .inputrc in your home folder and put the following four lines inside:

"e[A": history-search-backward
 "e[B": history-search-forward
 set show-all-if-ambiguous on
 set completion-ignore-case on

Once you do, open up your favourite Terminal Emulator (here are our favourites for OS X and Linux) and give a try.

The single most useful thing in bash [Coder Wall]


Comments

    Good :D

    Last edited 25/04/13 3:49 am

    In the picture there are backslashes on the first two lines but in the code you left them out.
    It doesn't work without them, I've tried.

      Sorry about that -- production issue. Backslashes reinstated, thanks for the pointer.

Join the discussion!