2

Is it possible when I press Ctrl+r and after this, for example, press the letter a, then using the up and down arrow key to search only the commands in the history that start with a? Or if I type ssh and then use the arrow keys to search commands that start with ssh.

Is there a script that can implement this?

1

1 Answer 1

3

You can even avoid the need of typing Ctrl+r by adding these two lines to your ~/.inputrc:

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

Up and down arrows will continue to browse your history if you press them at the bash prompt. But it will search for a command starting with the text to the left of the cursor if you type the beginning of a command like ssh.

2
  • Thanks, it's working. But with pressing ctrl+r it doesn't work, which is not a problem because only pressing a letter and then arrow key is faster. Just making a note. Is there a shortcut that can clear the active command? In Windows command prompt pressing ESC clear the typed commands and return the cursor in the beginning but in linux pressing ESC doesn't do that. Jul 7, 2015 at 17:24
  • @user1800997 See my answer here Jul 7, 2015 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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