4 ms·
TIL I can use ctrl+R to search bash history! This is going to save me a lot of time going forward!
by Wowfunhappy 8y ago
TIL I can use ctrl+R to search bash history! This is going to save me a lot of time going forward!
- jaster 8y agoAdditional tip: if you overshoot and miss the command you wanted by hitting ctrl+R too much times (as it happens sometime when looking for an older command), you can go forward with ctrl+S. [EDIT: As Hikikomori pointed (thanks!), I got my shortcuts mixed up, ctrl+S is the shortcut for zsh, and the equivalent for bash is ctrl+shift+R] (ctrl+S and ctrl+R are based on emacs shortcuts, where ctrl+S is search and ctrl+R is reverse search)
- Hikikomori 8y agoDoesn't work on GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) ctrl+shift+r works though.
- jaster 8y agoYep you're right, I got my shortcuts between bash and zsh mixed-up. I edited my post, thanks for the correction. (Not sure why bash did not go the obvious route here, I guess they already had something on ctrl+S when they implemented forward search...) EDIT: actually, you can activate ctrl+S for search-foward on bash by using `stty -ixon`. See more info about why here https://unix.stackexchange.com/questions/141422/searching-history-in-bash-forward-after-backward https://unix.stackexchange.com/questions/141422/searching-hi...
- fnord123 8y agoctrl-s is usually for pausing the terminal (where ctrl-q resumes it). https://en.wikipedia.org/wiki/Software_flow_control https://en.wikipedia.org/wiki/Software_flow_control
- 0db532a0 8y agoNote that your terminal emulator needs to pass the ctrl+S through. ctrl+S won’t work by default in a lot of cases from personal experience.
- asicsp 8y agoI rarely use ctrl+r, because most of the time I'm searching based on command name, which is at the start (unless it is in pipeline, etc).. so, I use this instead in `.inputrc`: # use up and down arrow to match search history based on typed starting text "\e[A": history-search-backward "\e[B": history-search-forward
- Wowfunhappy 8y agoThis is wonderful, thank you!
- 0db532a0 8y agoThis is actually a general feature of the GNU readline library, which a lot of programmes including bash use. For instance, a lot of REPLs like ghci use it. https://linux.die.net/man/3/readline https://linux.die.net/man/3/readline https://tiswww.cwru.edu/php/chet/readline/rltop.html https://tiswww.cwru.edu/php/chet/readline/rltop.html
- majewsky 8y agoAs does my favorite underappreciated Unix CLI tool, units(1). $ units --verbose You have: 1 mile * 20 pounds force You want: joule 1 mile * 20 pounds force = 143174.38 joule 1 mile * 20 pounds force = (1 / 6.98449e-06) joule
- 0db532a0 8y agoI had no idea of that command. Thanks.
- JetSpiegel 8y agoFor dumb terminals, you can also use rlwrap: https://linux.die.net/man/1/rlwrap https://linux.die.net/man/1/rlwrap
- craftyguy 8y agoNow you should try fzf and take your command searching to a whole new level with fuzzy find! https://github.com/junegunn/fzf/wiki/Examples#command-history https://github.com/junegunn/fzf/wiki/Examples#command-histor...