Christian Mayer's Weblog

Reverse Search History in Bash

You can search the history of previous entered commands in the Bash shell by simply hitting Ctrl+r keys. Enter a string you want to search for. By hitting Ctrl+r again you can search the history for a given string backwards to the end.

(reverse-i-search)`blog': cd ~/work/dev/blog/

The i stands for incremental.

This is a trick I use often on long lines. Consider this was your previous executed command and you now want to vi the same file:

$ ls ~/this/is/a/very/long/path

You simply want to change the ls to vi. Of course you can hit the Arrow-Up-key and then go the whole way backwards to the left beginning of the line using the Arrow-Left-key. (Or on OS X with bigger steps by holding down the Alt-key and pressing the Arrow-Left-key.) But you can do it in a more simpler way than that. Just press Ctrl+r and search for ls. Now you are instantly at the first position of the line. Hit Esc to exit the search and replace ls at the beginning with vi. Done.

Posted on .
Categories: Productivity
Tags: Bash, Shell, Terminal

Imprint | Usage | Categories | RSS Feed
Copyright © 2006 by