Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In the terminal, I can type CRTL+R to search for a matching command previously typed in BASH. E.g., if I type CTRL+R then grep is lists my last grep command, and I can hit enter to use it. This only gives one suggestion though. Is there any way to cycle through other previously typed matching commands?

share|improve this question
    
Keep hitting Ctrl+R. –  Sukminder Apr 24 '13 at 2:10
1  
@Sukminder You don't consider that an answer? –  Hauke Laging Apr 24 '13 at 2:25
    
@HaukeLaging: Yes, perhaps ;) if I read the Q correctly. –  Sukminder Apr 24 '13 at 2:32
1  
@Sukminder Then you should copy it into an answer, enabling yourself to get the bravely earned upvotes and this question to get closed (as solved). –  Hauke Laging Apr 24 '13 at 2:33

2 Answers 2

up vote 23 down vote accepted

If I understand the question correctly you should be able to cycle trough alternatives by keep hitting Ctrl+R.

E.g.:

Ctrl+R grep Ctrl+R Ctrl+R ...

share|improve this answer
1  
+1 -- FYI -- you can also search forward as per this StackOverflow answer. –  Jordan Arseno Apr 24 '13 at 21:14

You can also set up the up and down arrows to do a slightly different search by adding these lines to ~/.inputrc:

"\e[A": history-search-backward
"\e[B": history-search-forward

Instead of searching for a substring anywhere in the command (like Ctrl-r) it will search for a command starting with the text to the left of the cursor. For example, if I run these commands:

$ ls bart
$ ls fools

then type ls and press Up twice, it will show ls bart and the cursor in the same place. Compare with Ctrl-r, where it would find the ls twice in the last line, so you'd have to press it once again to find the previous line.

These approaches both have their strengths, and both of them can save a lot of time.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.