My 5 Favorite Linux Shell Tricks for SPEEEEEED (and efficiency)

preview_player
Показать описание
My favorite tricks for becoming a Linux Shell Speed Demon (this assumes Bash/readline)

1:04 - sudo !! - re-run previous command with 'sudo' prepended
1:53 - ctrl-k, ctrl-u, ctrl-w, ctrl-y - cutting and pasting text in the command line
3:24 - practical kill/yank example
4:04 - use 'less +F' to view logfiles, instead of 'tail' (ctrl-c, shift-f, q to quit)
6:25 - ctrl-x-e - continue editing your current shell line in a text editor (uses $EDITOR)
7:54 - alt-. - paste previous command's argument (useful for running multiple commands on the same resource)
9:18 - reset - resets/unborks your terminal

Рекомендации по теме
Комментарии
Автор

~~~ Timestamps to specific sections are in the description! ~~~

tutoriaLinux
Автор

i really love the fact that you wrote exactly what you are going to explain in the description with timestamps!

hellangel
Автор

> Bang bang
> password shot me down
> Sudo .. BANG BANG
"Torvald Sinatra"

GBGSK
Автор

Instead of <alt .> you can also just use !$ the same way you used !! in the first tip. There's actually a lot of notation for this which is terminal agnostic and supported in zsh as well as bash and probably others. For instance !-2 gives you the command before last, !-3 the one before that etc. $ on the end gives you the last argument of that command. !^ gives you the first argument, !:2 or !* gives the second argument. All of these things can be combined too, for instance !-3:2-$, which gives the second to last argument of the third-last command or !-3:2-3 which gives the second and third arguments to the third last command. Hard to keep straight at first but a very powerful way of getting around once you jam it into your head.

whiskeytuesday
Автор

"Alt + backspace" is more useful than "ctrl + w" in my oppinion. While the latter only stops at whitespaces, the former also stops at special characters, e.g. slashes, so you can edit your way to parent directories much faster.

HenrikAlsingFriberg
Автор

If you ever need to purposefully mess up a terminal like for 9:47, I've found the command "sleep 1 | vim" will do that consistently on any terminal.

jony
Автор

you had me at `sudo !! `
shaking my head at the amount of time i've wasted not knowing about this...

ernestogutierrez
Автор

I've been programming professionally for 40 years, most of that in the Linux world, and it's amazing the learning process never ends.

jplflyer
Автор

Another nice trick worth mentioning is reverse search (Ctrl + r), where you can type a part of your command and it'll bring on the last command entered with the expression in it. You can see older/newer commands by pressing Ctrl+r and Ctrl+R respectively.

It's a bit more common so maybe not really a trick, but still some people might not know about it.

mostafafarzan
Автор

i could definitely have a beer with this guy.

Barbarian.Streisand
Автор

VERY useful tips here, I plan to start using them regularly. You’re proving to be my most useful resource on YT in my Linux journey. Also enjoying your sysadmin series.

ChunkyDrew
Автор

Good video. I learned a couple of new tricks!

One trick I knew already and always use is the Alt-<dot> thing. I describe it to others this way - Alt-<dot> brings up the last "word" of the previous command. Think of it as an object. So you do ls /tmp/file. Now /tmp/file is the object. Want to know more about the object? Type ls -l Alt-<dot>. Contents? - more (or less) Alt-<dot>. File's junk - rm Alt-<dot>.

But what's more is say you have this in your history:

501 touch /tmp/file
502 ls /tmp/file
503 echo file?
504 uname -a
505 history

Typing Alt-<dot> at the command prompt will bring forth "history". But typing another Alt-<dot> will bring up "-a". Another one and you get "file?". One more and you get "/tmp/file". So if you want that Alt-<dot> object because it was say a filename object but it was not the last word of the immediately preceding command then keep hitting Alt-<dot> until you get back that file object.

AndrewDeFaria
Автор

11 minutes later and I don't know how I survived without these tricks for so long. Great stuff man

elijah
Автор

Great video! What I use probably the most is Ctrl+r to quickly search the command history. By using Ctrl+r you can go to the next hit and with Ctrl+R to the previous.

tobiassinghania
Автор

Huge Thanks for the 2 shell videos you've made. Been using CLI over a decade but did not know any of these tricks and have always found it slow and clunky when compared to the gui. Well no more, not after these massive quality of life improvements... Been 6 months since I watched these videos but I still think of you and smile the endless times a day I use these tricks!

momashi
Автор

I remember a while back you saying your co workers would give you a hard time about using advanced commands... I can see why, I have watched a lot of tutorials, some of the things you do I haven't seen ANYWHERE else. I like this channel because even if I go way back in your history everything is still relevant and useful. I've been subscribed but I forgot to hit the bell icon, so I didn't even know you were back. Glad to hear it though.

DDBAA
Автор

less -n helps a TON on large files (doesn't count line numbers). -S can be useful in logs as well (no wrap)

htl
Автор

How did I not know about less +F? This literally changes everything in my job!

TheDave
Автор

Great idea with the less +F <file> , I prefer using regular old less <file> then pressing shift+G, it takes you to the bottom of the file and you can scroll up without gluing.

joachimjohansen
Автор

Holy cow, it's been 12 years since the last time I used Windows on my home PC, and I do use the CLI a lot, yet I didn't know some of those tricks. Great work!

AleksandarBosakov