Or just use fish shell. Rarely need ctrl+r anymore.
history 500 | grep *snippet of command*
Atuin Magic Shell History is pretty good.
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)
history | grep thethingyou'relookingfor
deleted by creator
Blasphemy
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
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
Ctrl+R
https://atuin.sh/ Does all that and a lot more, like showing if the command succeeded and which directory it was run in
What the fuck!? How am I only learning this now, after years of linux as daily driver?!
Shit is usually a pain in the ass. The challenge is divining how much of a pain in the ass something has to be that someone else might have made a solution for it.
I didn’t know you could ctrl+shift+c to copy in the terminal until a month ago when my linux n00b wife said "there has to be a better way to do this. I’ve been right clicking to copy for 10 years.
most DE’s have a thing where you can paste highlighted text using the middle mouse button
It’s also independent from the Clipboard so you can do it while keeping your clipboard
Middle mouse button?!
Most mouse wheels can be clicked in place of the middle button, which has been removed from most modern computer mouses.
It’s also known as mouse 3 if you need to find it on your mouse or want to bind it to something else.
And ctrl + shift + v to paste, just in case
If that doesn’t work, Shift + Insert.
you can also just use ctrl + insert for copy and shift + insert for paste.
I used to have shift insert in my muscle memory from Windows, but since my job has used a Mac since 2020 it’s fallen out. I never knew Ctrl insert was copy, that’s nifty! Another tool in the arsenal. It will be useful when copy in select isn’t set and I don’t know how to set it up lol.
I have always used ctrl/shift insert, I never got used to ctrl c/v. Glad you have new tools!
MinGW can do that, too. Useful for Git.
Ctrl+c to copy, Ctrl+v to paste, Ctrl+z to undo last change (chain it multiple times to reverse time) hopes this helps, ctrl+tab also changes applications on macos and Linux to my knowledge. If you know anymore let’s put them together
Just checking, because I learnt to type before I worked this out, and because surely someone reading doesn’t know: press tab. Bash will fill in file names from your current directory.
E.g. say you have files fred1file, fred2file, jim.
Type f then press tab, it will fill to “fred”. Then press 2 and press tab again and it will fill the full “fred2file”.
Have a play, it works in heaps of situations.
Bash will also do autocomplete for cli programs that have autocomplete functionality. Try typing:
git r<tab><tab>
you’ll see options for all the git commands that start with r. Often cli commands will have autocompletion for long (double dash) options.
If you want to see all the commands that have auto complete available, look in:
/usr/share/bash-completion/completions/
There’s a few other locations they can live, notably:
/etc/bash_completion.d/ ~/.bash_completion ~/.local/share/bash-completion/completions/
I don’t know if there are more or if there is any variation per distro.
You can also write your own bash completions. They can get pretty smart and context sensitive.
Pretty good beginning tutorial:
https://iridakos.com/programming/2018/03/01/bash-programmable-completion-tutorial
Congratulations! I remember where I was when I first learned it (in a noisy server room at the back of a machine shop).
Now pair it with FZF for fuzzy finding – it’s surprisingly easy to set up, just following any guide. It’s insanely useful. I find myself even doing things like typing:
$ xinput --disable $(xinput --list | grep -i touchpad | grep 'id=[0-9]\+' -o | cut -d= -f2) # Disable synaptic touchpad trackpad pointer
commands with these like comments on the ends as sort of “tags” so I can ctrl+r search for them later. Yes, I know I could just use a named function, but this is like the step just before that–before I know if I’ll be issuing the same command all the time, or just for the next couple weeks. (This one was from when I was resting my notebook on my laptop.)
I like this; I have a lot of commands that I don’t use often enough to justify an alias, but still need to rerun all the time. thanks!
As usual, that’s documented (we can RTFM).
Before trying ctrl-s, you may want to disable software flow control: run
stty -ixon
& add it to your initialization files. Otherwise, you’ll pause terminal output. ctrl-q resumes terminal output.stty
reveals terminal special characters$ stty -a ⁝ intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; … ⁝
These special characters/keys often perform special functions. To illustrate
- ctrl-d on empty input typically exits/logs out of interactive terminal applications (including shells)
- ctrl-u discards input (useful for inputs like password prompts that don’t echo input back)
- ctrl-v inputs next character literally (such as tab)
Use mcfly and it will be even better.
This but with FZF and
ag
I’m not going to say how long I used linux before learning this. It isn’t “this many days old”, but it may as well be.
I have 7 headless linux boxes running.
Hey! I’ve seen you before! You’re the unhinged jackass noticer!
…i looked in your comment history for too long to figure out why though. https://lemmy.world/comment/18001123
Wait till you learn about
!?
.^r is superior, though.
This is what I love about Linux - always learning new things!
I’m shocked how far I had to scroll down before it was mentioned, I was getting scared I would have to say it lol
Even quicker with zsh or atuin: write the first few letters then arrow up to cycle through all matches
Even quicker with fish: Write the first few letters then it auto-suggests the last-run command matching that prefix (and then you can still arrow up to cycle through all matches).
(There is also a zsh plugin for that, called zsh-autosuggestions.)
A lot of stuff assumes Bash, so occasionally when the syntax differs its slightly annoying; sometimes you have to modify a few lines of a file or something (or run it as in Bash manually). Fish is so nice though. It really should replace Bash for almost everyone. If you really need Bash you can still use it.
With script files, you can (and should regardless of Fish usage) put a shebang at the top, like
or
. Then it will run with Bash as you’d expect.
I also recommend not setting Fish as your system-wide default shell (since then a missing shebang will cause it to run in Fish), but rather just have your terminal emulator start
fish
by default.And yeah, outside of scripting, if I notice a command requires Bash syntax (which you can often tell from Fish’s syntax highlighting turning red), then I just run
bash
, execute the Bash command in there and thenexit
back out of there.Having said all that, I’m not trying to take away from your point. If I wasn’t just joking around, I would caveat a Fish recommendation just as much.
Yeah, it’s just some scripts that come with programs sometimes not including that is the issue. Like I said, it isn’t a big issue, just occasionally requires small edits if you try to run the script in Fish, or, like you said, running them with Bash.
I main ZSH and I’ve been CTRL+R’ing for years damn here I am a fool
Glad to be of service
I like to imagine someone added it in for their own personal use and told nobody because surely they are the only one.
It was publicized as part of
readline
, I think.…in like 1989.