Save memory and typing when arrow searching through history

echo '\n"\e[A": history-search-backward\n"\e[B": history-search-forward\n"\e[C": forward-char\n"\e[D": backward-char\n' >> ~/.inputrc
Appends 4 configuration lines to your ~/.inputrc which allow you to seach history taking into account the characters you have typed so far. It is taken straight form Go there for a complete description (grep for "Incremental history searching"). Not sure about the limits of this (which OS's/terminals), but probably anything unix/linux like will do. Changed my life :)
Sample Output
### Start typing a command, say "nm", 
$ nm      # Realize you've done this before, so just press up arrow
$ nm /usr/bin/wine       # Bash completes from history ignoring anything not starting with "nm"
### Not the one you wanted? Just keep hitting up arrow until you find the one you want.
$ nm /usr/bin/wineserver
### Hit down arrow to go back.
$ nm /usr/bin/wine      # This is like normal up and down arrows but taking first characters into account.
### Need to be more specific? Note that the cursor is still after the "nm" that we typed at first, so if we hit "a" it shows this:
$ nma /usr/bin/wineserver
### ...but then, another press of up/down arrows and, voila, we get:
$ nmap -sUT -p- localhost
### Just go ahead and hit enter (you don't need to be at the end of the line) and it runs:
Starting Nmap 7.21 ( ) at 2020-02-29 09:20 XGT
Interesting ports on localhost (
Not shown: 131045 closed ports
22/tcp    open          ssh
[bla, bla....]

By: temach
2015-01-15 09:47:49

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: