Skip to main content
Welcome guest. | Register | Login | Post

Ctrl-R in the Bash Shell

Recently I came across the command Ctrl-R in the bash shell. It allows you to search and browse your bash history.

For instance you ssh into your server every day, in between each ssh you do a bunch of other things, this makes in impractical to use the Up arrow key to go through your history to find the command. Instead hit Ctrl-R, and start typing ss, it will search your bash history for the last time you used a command with ss in it:

(reverse-i-search)`ss': ssh

You hit 'Enter' and the line will be executed.

If you hit Ctrl-R again in will go back again in your history to the previous time you used a line with ss in it such as:

(reverse-i-search)`ss': vim /etc/ssh/sshd_config

If you wish to change your search parameters just hit the backspace key and write your new search, e.g.
[backspace] [c]
(reverse-i-search)`sc': screen -r

I hope this helps people who've become annoyed with hitting the Up arrow all the time to get at yesterday's command!


I've been using this

I've been using this feature for so long I never even thought of writing a tip about it :S . It's very useful!

By the way, it's important to note the phrase you search for doesn't need to be the beginning of the command line. You can search for the commands in which you used a particular program, but you can also search for the commands in which you did something to a particular file.

Comment viewing options