8

I keep fairly long bash history and sometimes when I search for something with bash reverse search function(Ctrl+r) I end up at the beginning of search history and I still did not find what I needed and then I would like to move back to the end of the history file. One option is to use forward search function(Ctrl+s) which moves closer to the end of the history or execute #, but is there also a keyboard shortcut to move directly to the end of bash history?

  • 2
    history will show you all bash commands made.. – ryekayo May 26 '15 at 13:41
4

There is the readline function end-of-history default mapped to (M->) but if used during reverse searching it exits the reverse search prompt.

A possible workaround/trick

Start string search

Instead to use reverse search you could use history-search-backward and history-search-forward (default unmapped) mapping them to up/down (very useful) in your .inputrc:

# up-down arrow to search in history
"\e[A":history-search-backward
"\e[B":history-search-forward

So after you have typed you could reverse search pressing up (instead of Ctrl-r)and when you want to return to the end of the history you can use the end-of-history function by press (M->)

This way "The search string must match at the beginning of a history line" so if you search for ls -ltr you have to type ls and then press up key.

Substring search

if you want "The search string may match anywhere in a history line" you have to use history-substr-search-forward and history-substr-search-backward:

# up-down arrow to search in history
"\e[A":history-substr-search-backward
"\e[B":history-substr-search-forward

This way if you search for ls -ltr you can type ls but also ltr before to press up.

http://www.gnu.org/software/bash/manual/html_node/Commands-For-History.html

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.