Making History with Bash

This is a nifty little trick for making Bash a little more intuitive (for my taste). Usually, when you press the up key, Bash will bring back the last command you typed. This is cool, but what bothers me is that sometimes I start typing a command and then remember I executed it before. So I press the up key and… Bash shows me the last command, disregarding what I typed. What I want it to do is search history for things with the prefix I entered.

Here’s what you do to achieve this. In your inputrc file (~/.inputrc for personal configuration, /etc/inputrc file for global configuration), add the following lines:

"\C-[OA": history-search-backward
"\C-[[A": history-search-backward

"\C-[OB": history-search-forward
"\C-[[B": history-search-forward

The weird symbols at the start of each line represent up/down arrow keys in keypad/ANSI modes. I wish Unix configurations would use proper readable symbols, but a man can only dream.

Moving Around with Bash

Little things matter. I’m often amazed of how I can feel I mastered a certain tool or technology, only to discover I’ve missed some basic way of using it. It happened to me on Windows a couple of weeks ago when I discovered cool keyboard shortcuts, like Win+E (which opens My Computer), or on Eclipse when I found out there is a menu that finds everything. On Linux, I’ve found that this happens all the time. Now, finding out how to use awk or sed is one thing, and it requires learning a complicated tool. But there are a lot of little things that are so easy to pick up, that it’s a shame that people miss them. Playing around with directories is so common in a Unix shell, and there are so many tricks you can use.

The basic way of moving around is, of course, cd path/to/dir. So far, so good. What more can you do?

Read More