Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Programs like matlab/octave and I'm sure many other ones allow you to start typing a command, and then hit Up to recall the last command that starts with the typed characters.

Common linux shell bash doesnot do this. Is there a different shell that does? I'm not asking how to find out the last command, I'm asking if there's a shell that's a little friendlier.

share|improve this question
2  
Not suggesting a different shell, hence the comment instead of answer. Have you tried the Ctrl-r reverse incremental search feature? Alternatively, !foo will run the last command you entered beginning with foo. –  jw013 Sep 14 '11 at 17:18
    
Thanks! I knew about ! but if I want to run !rm then it gets creepy –  Mikhail Sep 14 '11 at 19:17
    
Which is why I prefer Ctrl-r because you can interactively edit before hitting enter. For a 2 step approach you can do !rm:p to just print the expansion without running it. –  jw013 Sep 14 '11 at 20:13
add comment

3 Answers 3

up vote 3 down vote accepted

Bash does allow this when you have the following uncommented in .inputrc:

# alternate mappings for up/down arrows to search the history
"\e[B": history-search-forward
"\e[A": history-search-backward
share|improve this answer
    
This is wrong. It's not page up/down, but arrow up/down. –  Daniel Beck Sep 14 '11 at 17:32
    
@Daniel: Oh yes, I forgot to change the comment after changing the keys, but it was only the comment which was wrong. –  paradroid Sep 14 '11 at 18:00
    
Thanks! On the side note, is there an actual shell that's better? –  Mikhail Sep 14 '11 at 19:22
    
@Mikhail: That would be a subjective matter, but I have not used anything else on Linux apart from iPython and bash would not be so popular if there was something much better. Some people seem to prefer zsh, but don't know much about it. –  paradroid Sep 14 '11 at 20:25
    
@Mikhail Use whichever is default (i.e. presumably widely used, well-tested and well-integrated), unless you have specific requirements only a different shell can (easily) solve. –  Daniel Beck Sep 19 '11 at 12:13
add comment

Bash actually does it, when you configure it to do so. Put this in ~/.inputrc:

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

Then, up and down arrow keys will search through history using the prefix of the current command up to the cursor.

These functions are unbound by default. There are other history search commands, see here.

share|improve this answer
add comment

You want to use the forward and reverse history search. From bash(1):

   reverse-search-history (C-r)
          Search  backward  starting  at  the current line and moving `up'
          through the  history  as  necessary.   This  is  an  incremental
          search.
   forward-search-history (C-s)
          Search  forward  starting  at the current line and moving `down'
          through the  history  as  necessary.   This  is  an  incremental
          search.

Just hit ^R and stat typing, it does exactly what you request. Press ^R multiple times to browse through the hits.

share|improve this answer
add comment

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.