User login

Much smarter command line history up/down behavior - with search

You may know about ctrl+shift+R for reverse case-insensitive search (or whatever it stands for) and that is still useful if you remember one very unique keyword from the middle of a command.

Far more useful, however, is a simple extension to your bash to make command line up (and down) arrow traversing of the command line history restrict its results based on the first letters you type. For instance, type g and press the up arrow then all the grep, gvim, and git commands you have used recently come up, and none of the rake, drush, cd, and ls commands. Type gi or git before using the up arrow or down arrow and you'll have only the git commands you've typed before.

How to set this up in Ubuntu:

sudo vi /etc/inputrc

Then add the following or uncomment/modify existing lines to look like this:

# alternate mappings for "key up" and "key down" to search the history
"\e[A": history-search-backward
"\e[B": history-search-forward

Restart the shell (close remaining windows and open a new one) for this to take effect.

Tip courtesy Stefan.

Searched words: 
modify command line bash Bourne again shell to search history based on initial letters up down keys autocompletion pager

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.