The Coolest Thing You Didn’t Know Bash Could Do


There are few things that help one’s efficiency more than being good with his preferred shell. Many know of the ! option within bash that allows one to retrieve and run commands from history automatically.

You simply start with a ! and add the first few letters of a command you’ve recently run, and Bash will run that command for you. I don’t suggest doing this with rm commands, by the way. 🙂

thor ~ $ !net

executes for me…

thor ~ $ netstat -ntu | awk '{print $5}' | grep -e ^[0-9]

So, yeah…pretty standard.

What’s even cooler, though, and far fewer people know about, is the ability to search through your history rather than having to guess with the ! option.

Just type ctrl-r from the bash prompt and you’ll get this:


Now start typing something you’ve run recently and Bash will intelligently search your history and autocomplete your commands for you, based on how recently you ran them. Just press enter to run it, or press escape to edit it first. ::

Related posts: