Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Last year a friend taught me about the bash trick "CTRL-R" <start typing 'ssh' or some other previously run command> on the command line for reverse history searching, and it is an amazing time saver. It acts as a great alternative to #8, "Find the last command that begins with “whatever,” but avoid running it"

$ !whatever:p



I use up-arrow for that. My .inputrc has:

    "\e[A": history-search-backward
If you don't type anything, it acts exactly as the old up-arrow.


Or in ~/.zshrc:

    bindkey '\e[A'  history-beginning-search-backward


An important addition to that is to repeatedly hit ctrl-r to cycle through the matching commands in the history.


How do you reverse the search? <S-C-R> didn't do it for me. Either way this could be a good substitute for what I do now, tediously grepping .zsh/bash_history...


If by reverse you mean going forward instead of backwards, that should be done with Ctrl-S; it does not work in Bash though, since Ctrl-S locks the scrolling of the terminal. I believe this behavior can be overridden, through some .xinputrc settings perhaps, but I haven't still found enough motivation to look it up!

edit: ok, I've found this: http://wiki.archlinux.org/index.php/Bash#History_search


I'm pretty I learned this from reading an article on HN... anyone got a citation for me?


Perhaps my article "The Definitive Guide to Bash History?"

http://www.catonmat.net/blog/the-definitive-guide-to-bash-co...




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: