Friday, March 31, 2006

bash tip: search command history

from my previous post on ksh hotkeys vs bash hotkeys, i mentioned on how to use hot key to do search on command history, which is using ctrl-r
but i also mentioned that i'm not sure on how to use this key to go to the next or previous match command. i found it now :)

once you hit ctrl-r to do a "reverse incremental search". as you type, bash will search your command history and auto-fill the most recent command that matches the pattern you type in. hit ctrl-r again to go to the next most recent match. just hit ctrl-r again & again until you found the command you looking for. and if you want to go the previous match command, you can hit ctrl-s, but make sure you do this first:

disable the default terminal setting for ctrl-s & ctrl-q which is to lock & unlock your terminal.
$ stty -ixon

No comments: