Ctrl-R - the magical key combination that can make you smarter and better looking

8 Antworten [Letzter Beitrag]
andyprough
Offline
Beigetreten: 02/12/2015

The terminals we all use, such as the MATE Terminal in my Trisquel 10 installation, have a magic key combination that can make you smarter and better at Linux stuff than ever before. In fact, I will propose that it can make you smarter, healthier, and better looking!

It's rarely discussed, and so for many Trisquel users, this may be news to you.

The key combination is Ctrl-r (push the Control key and the letter "r" at the same time).

What this magical little wonder will do is remember all your old commands for you. If you ever (like me) spent half a day looking through old online posts for a specific command to run in the terminal, only to forget to write it down so you could use it later - Ctrl-r comes flying to the rescue for you!

For example, I'm always trying to remember how to use the youtube-dl program to download just the audio version of a song or a podcast. I don't want the big video file, I just want to listen to it. There are many ways to achieve this, and hundreds of web pages that give conflicting advice on the best commands to run. After a lot of trial and error, I usually land on the following command:
youtube-dl -x --audio-format opus https://[link to some video of a song or a podcast]

But then I always forget to write it down in my list of handy commands, and so a couple months later when I need it again, I have to start trudging through lots of bad internet posts again to find the one I need.

That's where Ctrl-r comes to the rescue! At the command prompt, just push Ctrl-r, and it will say:
(reverse-i-search)`':

Now, I just start typing in some word I remember from my earlier command, in this case the word "opus", and Ctrl-r brings up my old command for me!
(reverse-i-search)`opus': youtube-dl -x --audio-format opus https://[link to video]

I can now hit the 'Enter' key to run the command again, or I can use the left and right arrow keys to scroll through the command and make changes before running it.

Magic! And suddenly I'm not as senile and stupid and forgetful as I once was. Ctrl-r makes you smarter! And you are less stressed, so now you are healthier and better looking! Smarter and better looking - thank you Ctrl-r!

Now we just need a key combination to lose weight....

Magic Banana

I am a member!

I am a translator!

Offline
Beigetreten: 07/24/2010

GNU Bash uses GNU readline. You can find many other such commands in its man page:
$ man readline

Those commands are well known to those who use Emacs (but readline can be configured to use VI bindings): C-g aborts (for instance a reverse search with C-r), C-p gives the previous line in the history, C-n the next line, C-a moves the cursor to the beginning of the line, C-e to the end, C-f moves the cursor one character forward, C-b backward, M-f moves the cursor one word forward, M-b backward, C-d deletes a character, M-d deletes a word forward, M-Del backward, C-k "kills" everything until the end of the line, C-t transposes (switches) characters, M-t transposes words, M-u converts to upper case until the end of the word, M-l to lower case, M-c capitalizes it, C-y pastes (whatever was cut with M-d, M-Del, C-k, etc.) and following it with (possibly several) M-y allows to paste what was cut earlier, C-_ cancels, etc.

In what I wrote above, "C-" is what is more commonly written "Ctrl+" and "M-" is "Alt+" on most keyboards. Some key bindings (typically M-f) may be caught by the terminal emulator but any good such emulator allows to disable that (in the Preferences).

andyprough
Offline
Beigetreten: 02/12/2015

A lot of that is just cursor movement, which has never impressed me as a time saver all that much. Not nearly as useful as Ctrl-r to search history.

However, transposing words could really come in handy. And I could see deleting to the end of the line, or doing a quick word delete could be useful. I can see how these would all be much more useful key combinations if I were spending my entire day in emacs doing nothing but programming. Keep my hands on the keyboard as much as possible.

One of these days I'll have to set aside a month to immerse myself in emacs, maybe I'll become an emacs cursor movement proselyte. Convert to the Church of Emacs.

I'll bet there's a key combination in there somewhere that will make you lose weight.

Legimet
Offline
Beigetreten: 12/10/2013

Yes, these shortcuts also work in other readline programs, e.g. the Python interpreter.

jahoti
Offline
Beigetreten: 07/31/2021

This is incredible- thank you!

gaseousness
Offline
Beigetreten: 08/25/2020

Something like

youtube-dl -x -f 'bestaudio[acodec!=?mp1][acodec=?opus]/bestaudio/worstvideo+bestaudio/best' 'LINK'

EDIT* appears to be an audio download way some may want to consider that seems to prefer opus, and boycotts mp1 (not sure if mp1 is a real audio codec but as an example), but will fallback to others if opus ain't an audio option the server claims to have? If no audio only option, will download both audio video and extract the audio?

andyprough
Offline
Beigetreten: 02/12/2015

That works. Seems to do the same thing as youtube-dl -x --audio-format opus https://[some video]

I guess your method would become more desirable if the download could not be converted into opus for some reason. But, since the conversion is always post-download via ffmpeg (I think from what I've observed), opus SHOULD always be available.

gaseousness
Offline
Beigetreten: 08/25/2020

"That works. Seems to do the same thing as youtube-dl -x --audio-format opus https://[some video]"

Yes, just won't convert like a m4a to opus in the end, appears would skip downloading any video and only download audio if it can, but appears that might depend on if you had a config file set for youtube-dl?

andyprough
Offline
Beigetreten: 02/12/2015

>"Yes, just won't convert like a m4a to opus in the end, appears would skip downloading any video and only download audio if it can, but appears that might depend on if you had a config file set for youtube-dl?"

Yes, I should look into getting a proper config file. But for example, the song I just downloaded was just 2.14mb for the webm video download. After processing by ffmpeg to turn it into an opus audio file it actually INCREASED in size to 2.21mb. Neither of which is a problem. If I have to download a 500mb video in order to extract a 5mb audio file, that's when it would be a bigger issue.