When dealing with bash history, I find that too many people are still unaware of C-r (Ctrl+R or Command+R): press it and start typing unique bits of your past commands. If multiple commands match, cycle through them with repeated C-r presses.
Instead of aliasing common commands, I make heavy use of Ctrl-r at the command prompt to search the history.
So if I have a complex command I want to run several times, I'll type it out in full the first time. After that, I'll hit Ctrl-r and start typing part of the command until it shows the one I mean, then hit enter to run it.
For those who haven't used it, ctrl-r in the command line is the best thing in the world. It does a reverse-search over previous commands. Set your max history size to unlimited, and your CLI will remember /all/ commands you ever type, making it very easy to find long, strange incantations that you figured out once, so long as you can remember some small part of the command.
For example, How did I do that magical ffmpeg thing last time? Just hit ctrl-r, type ffmpeg, and keep hitting ctrl-r to find previous examples until I find what I'm after.
And the next lesson: C-r will search the command history (at least in most *nix shells). So when needing to do something but you aren't sure how far back it was (not on the screen or not recallable) but you know it is in the history and some text in it, just C-r <something> [C-r repeatedly until you get to the correct version].
I was today years old when I learned about CTRL+R. I've always just done history | grep
Also, I use zsh which filters history when using up/down arrows to whatever you typed. So you can do "git" [up] [up] [up] to cycle through all recent git commands which is super useful.
Interactive history search (^R) in Bash (and IPython) so awesome, it can't be overstated. I've become so addicted to it that I start almost any command with ^R now. For most of them, I've got them somewhere in history - and only if it doesn't find anything, I ^C and type manually.
For those unaware: CTRL+R in terminal will also change your prompt to search your command history. After typing, CTRL+R again to cycle through matches.
To be fair, I also have that alias and use CTRL+R. They are useful for different scenarios. CTRL+R when I know what command I'm looking for, but can't remember the full one. `history | grep -i $TERM` when I remember some part of the command, but not exactly sure. With that, I get a list of possible candidates to choose from, instead of having to do CTRL+R repeatedly to find the command I was looking for.
Great Atuin, that's amazing. Thank you, this is indeed a game changer for having a permanent history. I use ctrl+r for everything including commands I vaguely remember but know at least some letters
Agreed, but even nicer than control-r are the readline functions `history-search-backward` and `history-search-forward`.
Personally I bind them to up/down which on OS X at least involves:
# Put this in some file like ~/.readline-bindings
"\e[A": history-search-backward
"\e[B": history-search-forward
# And this in your ~/.bashrc or ~/.zshrc
bind -f ~/.readline-bindings
That way if you haven't typed any input it behaves like normal up (previous command), but if you've typed some characters it only retrieves matching commands.
My favorite bash trick is still Ctrl-O: submit command and advance history by one.
If you ever find yourself counting up-arrows to repeat a sequence of commands (that aren't worth scripting for whatever reason), next time, go to the top of the list and hit Ctrl-O. The result is the the command runs, and the one after it in the history is loaded into you prompt.
C-r will search what you type afterwards, (e.g., "C-r ssh" will then show me the previous command that starts with "ssh") whereas this tip seems to be searching to match what you've already typed. Pretty cool, IMO.
The usual reaction is :mindblown: :)
reply