My 5 Favorite Linux Shell Tricks for SPEEEEEED (and efficiency)
Ғылым және технология
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
My step-by-step project-based Linux course for beginners: www.udemy.com/course/hands-on...
Free Linux Sysadmin Course Playlist: • The Linux Basics Cours...
DigitalOcean referral link: m.do.co/c/0380a1db56a6
Patreon: / tutorialinux
Official Site & e-mail list: tutorialinux.com/
Twitter: / tutorialinux
Facebook: / tutorialinux
Podcast: kernelpanicpodcast.com
Пікірлер: 731
~~~ Timestamps to specific sections are in the description! ~~~
@planktonfun1
6 жыл бұрын
ctrl+a and ctrl +e goes to the start and last, I find myself using this most
@chaoswires2734
6 жыл бұрын
Thanks for tips! Few more useful commands. The easiest way to create empty file is typing >filename I also often need to convert unix timestamp to hooman readable form, "date --date=@your_date_in_unix_format" does the job.
@noele2980
6 жыл бұрын
i literally screamed when i learned the kill / yank
@DaleHawkins
5 жыл бұрын
Becoming proficient in emacs makes the editing commands second nature. 🙂
@priit7777
3 жыл бұрын
@@planktonfun1 but why? your keyboard also doesn't have home and end keys? much easier than some ctrl combinations.
i really love the fact that you wrote exactly what you are going to explain in the description with timestamps!
@weasel6205
3 жыл бұрын
Yeh, same, I was prompted to subscribe as my patience run out not because I should definitely learn the rest of the content but because,"ADHD," 🤣, prompted straight to subbing and turning notification on, lamo.
> Bang bang > password shot me down > Sudo .. BANG BANG "Torvald Sinatra"
@karlheinzneugebauer
3 жыл бұрын
BANG BANG rather reminds me of "Rammstein - Feuer Frei"
@vass0922
3 жыл бұрын
@@karlheinzneugebauer hey thanks thats a great way to remember that!
@hayksk
3 жыл бұрын
Nancy Sinatra :) ?
@karlheinzneugebauer
3 жыл бұрын
@@hayksk Had to google who that is. Appears to be the daughter of Frank. Interesting.
@hayksk
3 жыл бұрын
@@karlheinzneugebauer Yes, she is.
Instead of 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.
"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.
@tutoriaLinux
3 жыл бұрын
Solid advice! Will try to re-wire my brain to try it out.
@sarthaks95
3 жыл бұрын
Both are useful but for different cases. Clear entire arg or go word by word. Personally I use both depending on the case.
@richardcampbell2438
3 жыл бұрын
I use a Mac terminal and there is no Alt key, but ^w works just fine enough for me
@novimartyn
3 жыл бұрын
@@richardcampbell2438 On the Mac I think you need to use Escape instead of Alt
@ernestdesouza8888
3 жыл бұрын
@@richardcampbell2438 dump Ur mac if ur using Linux ! Actually anything is fine ...depends on the person !!!
I've been programming professionally for 40 years, most of that in the Linux world, and it's amazing the learning process never ends.
@JerryPenna
3 жыл бұрын
Yeah, I’ve used less a ton but not with other flags. I tried less +F but didn’t work.
@allen_joji
2 жыл бұрын
Do you still love programming ?
@jplflyer
2 жыл бұрын
@@allen_joji Yeah, I do. I'll eventually retire, but it's unlikely I'll ever stop programming. I'll do my own projects is all. My opinion about careers: you should find something you can be passionate about, that you want to do even if you weren't being paid. We spent far too much of our lives at our jobs, and do you want it to be soul-sucking? The last people I want to work with: the ones who see it as a job. They're only there for the paycheck. Yeah, if I won the lottery, I'd quit the day job. But I'd still program. I'd just get to pick what I work on.
you had me at `sudo !! ` shaking my head at the amount of time i've wasted not knowing about this...
i could definitely have a beer with this guy.
@cgme7076
3 жыл бұрын
Yeah, he seems like a cool guy
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.
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.
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!
Just came across this channel and I love it! Thanks for showing us how wonderful Linux can be and how to use it.
11 minutes later and I don't know how I survived without these tricks for so long. Great stuff man
Thank you so much Dave for sharing your knowledge, looking forward for future videos. Keep it up mate!
How did I not know about less +F? This literally changes everything in my job!
@nonconsensualopinion
3 жыл бұрын
Maybe it's overkill, but I always just use vim. It loads very quickly and gives me the ability to search all around any log, jump to the bottom, etc. vim logfile, shift-g to get to bottom, :q to exit. Done.
@SJmurov
3 жыл бұрын
@@nonconsensualopinion But does it follow?
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!
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.
@SeanNicholsEh
5 жыл бұрын
Can't believe I just upvoted a guy for messing up my terminal... XD
@tobiaskrischer9950
5 жыл бұрын
could not confirm: root@debootstrap:~# sleep 1 | vim -bash: vim: command not found root@debootstrap:~# /s
@iam3377
4 жыл бұрын
Vim is seriously the best text editor
@aeelinnannelie5651
3 жыл бұрын
It does not happened to me. Maybe because I have Neovim installed
@twb0109
3 жыл бұрын
@@iam3377 laughs in nvim
Great video! I consider myself a seasoned shell user since I've been doing this stuff for 30+ years but you've taught me some new stuff. Two things to add though to fix a borked terminal is "stty sane" and "echo ctrl-v ctrl-o". Excellent tutorial!
Thanks for the video. Although I am using GNU/Linux for more than 15 years, I forgot about !! and I didn't know about C-x-e. Thanks.
I already know I'm going to use that command line yanking so much, thank you!
Fantastic post Man! Wanted some Ninja tricks to share with my Students tomorrow and these are perfect! Thanks so much!
Nice work, dude! I love your videos, keep it up :D
Great tips, thanks for sharing! I'm proud that I knew a couple already but most are new to me. I'm going to incorporate these into my day to day for sure. The comment section is gold too.
Fyi, another nice thing about using less over tail is that you can put in some search terms before kicking on the live tail mode and they'll be highlighted. Ex. put in a /error|warning|critical then hit shift+F and as things scroll by, error, warning, and critical will be highlighted.
@beeeeep
5 жыл бұрын
You can even use & interested of / to filter what you like to see.
@ALTracer
5 жыл бұрын
| ccze --mode ansi also does that
@KirtFitzpatrick
3 жыл бұрын
I wonder if there is a way to get automatic highlighting like with bat.
8:52 LOL "Dammit Ubuntu. Ruin even..." Now I know you're a command-line warrior.
Love these hints and tricks, I'm probably pulling at least a few into daily life - Shot dude!
My recommendation for vim users: add ```set -o vi``` (or something like that, too lazy to look it up) to your bashrc, and use your favorite vi-keybindings in your shell (press esc to get into normal mode)
These videos are great! Looking forward to more and more in-depth practical and theory based tutorials.
@tutoriaLinux
6 жыл бұрын
Yeah, I've got some advanced ones coming -- in-depth systemd tutorials, compiling a kernel, writing your own syscalls. Woohoo!
Thanks for the tips! When I saw the alt+f/b, I realized how annoying it is without it. About less +F, it's great for one logfile, but I can do tail multiple logs with tail, which is sometimes useful: tail -f /var/log/something/*.log
Thank you!!! This video should never die!
Thank you for sharing information which is immediately effective and useful.
Sudo!! I hit the ground Sudo!! That awful sound Sudo!! My baby shot me down
Some of those I didn’t know. You saved me loooots of minutes for sure. Thanks!
first useful shell video tutorial I ever ran into
very informative, i often use for example "ssh " to repeat the last ssh ... command
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.
wow this is just wonderful, especially the reset command for me cos lately I have been using a remote shell and it usually gets weird after a while, but I tend to just manage...so this definitely works and I will be using it from now on, thanks!
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.
@josephknightcom
5 жыл бұрын
thanks
@frydac
3 жыл бұрын
try fzf, it makes ctrl-r a dropdown list (i think it opens a tmux pane on the fly iirc) and lets you search in a fuzzy manner. And also search for files like that, I can't live without it anymore..
@tobiassinghania3698
3 жыл бұрын
@@frydac yes, fzf is really awesome in various regards :)
I was expecting to be disappointed (didn't notice who published it before I clicked watch, lol) but I didn't know a single one of these, thank you! All of your videos are great.
Your awesome channel popped up in my recommendations. Subscribed!
Loved the "BONUS ROUND!" :)
Realy cool shortcuts. It helped me a lot. You are great!
Nice tips and clean explanation. Thank you
Thank you for all the work putting this together, and for teaching all us terminal plebs how to kick ass at terminal lol. Again, thank you!
BONUS tip was the best. I have the issue all the time especially after using gdb ... Thank you sir, U've earned a Subscriber
fabulous presentation - muchas gracias
Thank for the video, I already know someone of this tricks, but others were new.
as an adjunct to !!, I find I use !$ A LOT. This handy thing refers to the last argument on the last command. e.g. mkdir -p /home, then cd !$. This will be equiv to cd /home.
@jonatansmithtubed
3 жыл бұрын
Try 'ESC + .'
@KirtFitzpatrick
3 жыл бұрын
@@jonatansmithtubed What's esc + do?
@jonatansmithtubed
3 жыл бұрын
Kirt, it is "ESC" and the "." (dot) Repeat last argument
Nice collection. Thanks for the video!
Less +F is brilliant! That will be quite useful for me, thanks.
Super !! Thank you a lot!!! These were very useful tips.
Thank, I really appreciate less command explanation and would love to see more videos.
Thank you! Very informative.
Nice examples! Did learn something new! Thank you! I would also mention "Ctrl - r" for searching in .bash_history. Something I use often... Good work, guy!
Awesome vid!! Very helpful!
Very handy tips. Appreciated.
Thx for the ctrl-k, ctrl-u, ctrl-w, ctrl-y tip. I didn't know that one. Even works in Zsh.
Thanks!! really helpful commands!!
extremely helpful! thanks for the great video
Alt . is a winner! Thanks for the vid and the timestamps ^^
I actually found the --curses tangent to be useful. I have cursed ubuntu myself when it popped up in a gui. Great tips keep up the good work.
Great idea with the less +F , I prefer using regular old less then pressing shift+G, it takes you to the bottom of the file and you can scroll up without gluing.
Perfect tricks. thank you so much!
Very nice tutorial, thanks
very good tutorial, powerful commands, thank you.
I thought I knew a lot.... Great video... Thumbs up
Thanks for all your free content :)
Thanks for 'less +F'. There's also a program called multitail which I have been installing on servers I manage for quite a while. It lets you follow multiple log files at once, also colors.
@shanecole401
3 жыл бұрын
try using tail -qf foo.log bar.log and it will show new lines to both files ordered, and if one rotates and goes away but appears later keep tailing it, all as if it was just one file
Great tut. Very useful
These are veeeeeery helpful!! Thanks bro :D
less -n helps a TON on large files (doesn't count line numbers). -S can be useful in logs as well (no wrap)
@codeman99-dev
3 жыл бұрын
I almost always use `less -FRS` -F will "quit if one screen" or "there is no need for scrolling" -R will allow correct width calculation of control characters. Especially useful if you are piping a command and still want the color output.
@JerryPenna
3 жыл бұрын
Ok I’ve been using less longer than I want to admit. Will try “less -FRS”. 😂
For tip 5 you can just do "mtr !$" (last argument) or "mtr !*" (all arguments) which both have the advantage of not being terminal dependent (just relies on history). I think even without history "mtr $_" would work. Or you can even have a bit of fun "^ping^mtr^"
@osquigene
6 жыл бұрын
Yes, if you want the detail of that you can refer to 9.3.1 and 9.3.3 in bash manual. You can do stuff like, creating a file: touch A/B/C/d.txt then moving to the directory: cd !$:h # h: Remove a trailing pathname component, leaving only the head. You'll also see: ^string1^string2^ Quick Substitution. Repeat the last command, replacing string1 with string2. Equivalent to !!:s/string1/string2/. Similar things exists for parameter substitution (which I personally only use for file names/paths manipulation): www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion www.tldp.org/LDP/abs/html/parameter-substitution.html You have an example in the documentation that shows how this can be used: www.gnu.org/software/bash/manual/bashref.html#A-Programmable-Completion-Example
Sudo bang bang ! Something can never be forgotten 😂❤
Awesome tips, thanks a lot!
I did not know less' +F option. Thanks a bunch, I'm sure that'll come in handy.
Thanks a lot for these tricks.
The ctrl-x-e trick is great for small modifications to commands from your history as well. You can up arrow, or bang or history | grep or whatever to a previous long gnarly command, then hit ctrl-x-e to make easier surgical modifications to it.
Thanks for the video. Love it!
You are a blessing, man. Thanks!
These were great, thank you.
Great tips. Thanks!
Great vid bro. Thanks!
great one !!!...thanks for the video 😄
Just Wao, I am gonna use em. Thanks Dude!
Awesome stuff! Thank you very much :)
Good stuff! Also in addition to alt+. you can also do alt+# (as in 1 or 2, not pound) then alt+. and you'll get the next to last argument for 1, second to last argument with 2...and so on.
Excellent video!
Helpful man. Thank you.
Thanks for posting the Cheat Sheet; These things are soo handy for me.
Thanks i learned about ctrl + x + e and less +F.
Just making me want to try typing random ctrl and alt sequences on my command line to see what I can discover. Thanks!
Awesome video man, thank you :)
These tricks saved my day
awesome vid man !!!
bro at first i thought you are gonna say some interesting but not useful stuff, but it was great. Thanks for Sharing , Keep up
One of the best projects we had in university was building our own copy of bash (stripped down a bit obviously) from scratch in C. Even though I have built my own, I learn new stuff everytime i see videos like these.
This is awesome linux tips.
cool video bro. 2 min in and I already liked!
Dude I'm watching this in 2021 and this super helpful. Kinda regretting went KZread didn't recommend earlier
Many thanks! On linux since 1995, yet most of this was new to me.
@sashamc309
6 жыл бұрын
awuma whoah! you really should have known about !! or Ctrl+W. I'm working on the terminal for 3 years and I knew most of this.
@sign333b
5 жыл бұрын
@@sashamc309 congrats
@JerryPenna
3 жыл бұрын
1999 abs same feeling.