history 500 | grep *snippet of command*
I see so many people loving on atuin in the comments but I just tried it and don’t get it. It seems so much worse than the built in search. I guess it’s not for me.
Or just use fish shell. Rarely need ctrl+r anymore.
Atuin Magic Shell History is pretty good.
history | grep thethingyou'relookingfor
deleted by creator
Blasphemy
I see everyone posting about Ctrl+R, here’s a couple more useful CLI shortcuts you might enjoy:
cd - (change directory to $OLDPWD usually the previous directory)
git checkout - (similarly checkout the previous branch)
Ctrl+A (return caret to beginning of command, great when you forgot a positional argument and you were almost done typing the command)
Ctrl+E (similar to Ctrl+A but move to the end of the command)
Ctrl+L to clear the terminal screen, instead of typing clear
It’s too early to call me out like that.
zsh-history-substring-search
I lazily type part of the thing I want like “sys” and then ctrl+⬆️/⬇️ and
sudo systemctl start libvirtd
etc. appear like magic.More like ⬆️⬆️⬆️⬆️⬆️⬆️ mother fucker ⬇️
You know the one command I hate? CTL vs CTRL. There is no damned consistency I can see. Is it systemctl reboot or systemctrl reboot?
i’ve literally never seen ‘systemctrl’? it’s always ctl for the command-line utilities
Ctrl r
Almost, ctrl+R, ⬆️⬆️⬆️⬆️⬆️⬆️⬆️
set -o vi
ESC k /command
or just grep history…
I used to be like this but people seriously. CTRL+R
Do it. Don’t make this one of those things you’ve heard about and just never got around to trying. Open your terminal right now and CTRL+R and type any part of the command you did before. If the command you want is not showing first just hit CTRL+R again to go to the next one back.
DO IT.
Edit: I did learn from this thread today though that ZSH has it set to where you can just type part of what you’re looking for then hit up to do the same thing. Neat!
CTRL+R + FZF is the goat. You just need to vaguely remember the command and you’ll find it.
This changed my life when I discovered it. Also using
ag
as alternative to ack.FZF Vim plugin is also gold!
Holy shit. I just tried it.
ctrl+r
is a revelation! How the fuck did I not know about this?If you want to level up ctrl-r, upgrade to Atuin: https://atuin.sh/
You can empower Ctrl+r event more by using fzf. After I started using it, I can’t imagine going back to without it.
WHAT THE FUCJ IS THIS SORCERY BRO I’VE BEEN USING LINUX FOR AGES AND NEVER KNEW THIS BROOOOOOOOOO
Edit: I did learn from this thread today though that ZSH has it set to where you can just type part of what you’re looking for then hit up to do the same thing. Neat!
Fish too, it’s fantastic.
Everyone sharing their Ctrl+R tips, here’s my Control+R question:
How does scope work? Some command history only seems to exist in certain tabs.
Also sometimes I Ctrl+R in a tab then the command is there but I forget I need a different one first, so I ctrl+c but the next time I search for that original command somehow it doesn’t exist anymore.
I’m using the default terminal on Nobara (fedora based).
This actually doesn’t depend on your terminal but on the shell running inside it. Bash is the default on most distros. I have also frequently had this issue. There might be config to fix it.
I switched to fish instead of bash, and now I use fzf and the https://github.com/PatrickF1/fzf.fish plugin and it works GREAT. There might be a similar thing for bash, I don’t know.
That looks awesome! Thanks for the rabbit hole 😅
As far as I remember, there is a bash setting that controls whether the command history is written immediately after execution (in which case it is immediately available on all tabs/windows of the console) or after closing the session (in which case it will be available next time/potentially lost if the window is forcibly closed etc).
The default is the second one as far as I remember.
That said, I had changed to a more powerful one in zsh years ago, so it’s been a while…
Thanks, I worked it out. Not a setting as such, but you can use PROMPT_COMMAND to run an action to insert into history each time a prompt is run, as described here.
Though I have started down a rabbit hole of looking at other options for the shell.
history | grep then !cmd_number