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

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on everyone in this video I'm going to show you the five kind of like tricks so that made me much much faster on the shell as a sysadmin or a programmer a DevOps engineer or whatever the title is you're going to spend a huge chunk of your time working in a shell environment so it's worth investing some time into getting really fast the things that I found wastes the most time are things like typos while you're typing forgetting to prepend something at the beginning of a command and the kind of surprising one was poor navigation through log files I didn't know how quickly could get around a log file until I saw somebody who was much better than me doing it one quick note you already should know the basics of moving around in a shell so if you don't know the prereqs like navigating beginning or end of line moving through space delimited words in a command searching backwards through your shell history as you type if you don't know those things yet I've got a linked video in the card just click on that watch that make sure you're comfortable with that stuff start incorporating these five things into your daily work and you'll get a pretty huge speed boost okay so the first thing is something I use all the time when you run a command and you realize ah crap I had to use sudha for that instead of going up for the previous command and then going to the beginning of the line and i'm typing sudo as you might what you can do is just run sudo bang bang and you'll get prompted so the bang bang is one of the bang commands I'll actually do a separate video on those because they're pretty useful if you're working a lot on the shell with bash sudo bang bang just reruns the previous command with sudo prepended to the front so this previous command which was a find command that ended up looking at var log and some directories that it couldn't look inside of without sudo permissions now they simply run with sudo in the front super nice super quick useful I use it pretty much every day thing number two killing and yanking text that is cutting and pasting it or uncut it it's super useful you'll use it all the time because a lot of the time if you're navigating around a file let's say I want to eliminate the X args I'll navigate for word by word and then I want to kill the rest of that line to the end what I would do is use control K to cut to the end of the line and then I can you know run this or whatever if I want to yank the text back I can just use control Y and that's gonna give me back whatever I just cut so that's control K kill to the end of the line if I want to do the inverse of that which is killing to the I suppose it's the opposite is it the University opposite whatever the complementary action here would be killing to the beginning of the line which you can do with control you so control U cuts alt text before the cursor and again the yank command control Y works exactly the same it'll always just contain the last thing that you cut you can yank that back ctrl W which is kill word backwards is another really useful one if you just want to kill backwards word by word this will ignore symbols and other stuff it really just cares about spaces so it's space delimited words you can kill one at a time yank still works the same way using all those things together one of the nice things you can do is let's say you find yourself typing in a place where you'd use sudo bang bang if you already made the mistake one of the things you can do is you're at the end of the command and you realize damn it I need to do nice flow for this instead of ctrl a and then sudo enter if you want to keep typing at the end is control U that'll kill everything before the cursor then sudo and then ctrl Y that gives you everything back and then you're good play around with these a little bit they'll suddenly feel very intuitive after you know 30 seconds or a minute of playing around there's a table in the description below so you can like copy that to an index card or something and just have it sitting on your desk in front of you thing number what are we on thing number three I'd love love this one and I use it a lot if you are doing like DevOps is that men's stuff or even software development you are spending a lot of time tailing log files in fact instead of just grabbing the tail you're probably tail following I don't know let's just grab syslog and so this is one of those things where you're tailing the log and it's all nice and good but then you realize like Damon actually wanted something from earlier in the log or you got to a too late what you really probably should be doing is is instead of using tail with the negative F option use less plus F and what that will do is it's less so it just load the entire file into memory buffer but the nice thing that you can do is that it starts you at the end if you want to detach from the end if you don't kinda want to unglue yourself from there just hit ctrl C and then you can either scroll if your terminal supports that or just use keyboard shortcuts to move around and you have the entire file at your disposal so it's not just whatever number of lines tale gave you or you asked for if you ever want to reattach again just hit shift F ctrl C to get out of follow mode and then cue to exit the other thing is if you actually forget the plus F it's not even that important that you use the plus F so let's say you're just using less and you're looking through and it's like a huge huge file this can take a second but as you're paging down let's say with the spacebar you realize like oh this is not a 10 gig file it's much smaller so it's something I can I can actually load pretty quickly well then you can just shift F and it'll bring you right down to the bottom again that's a tiny bit iffy on huge files they'll take a long time because it will like I'm pretty sure it just does like a linear it loads the entire thing into memory and then sticks you at the end where data is still getting streamed in okay so that is les plus F and again shift F glues you back to the end ctrl C unglue Zoo and then q just quits so for my next trick when you're writing a command that might be a little bit more than what you're comfortable editing in a command line like a larger for loop or a bunch of for loop something that starts turning into something kind of script D but you still don't really care about saving it so we'll say for host and hosts do and then you're like I'd really like a new line here so like keep this nice and readable well the thing you can do is control hold down control and then X E and what that'll do is it'll pop you into a buffer for whatever is set to editor so that's the if you do like echo editor you'll see what your editor set to I don't really recommend doing this with like Nano it can have kind of confusing behavior but if you're using a more Emacs and that's just what your editor is set to I highly highly recommend using that every once in a while when you get yourself into trouble with like a really long line that you're editing and you just really would like the shortcuts that you're used to that's a lovely thing to do basically if you write and quit this it will actually pipe this into your shell and then it'll be executed so you can see it's just echoing out although the eye piece that I put in there it looks like one's incorrect and so what I get anyway fun useful basically switch to your favorite text editor to finish editing a command that's getting unwieldy in the terminal thing number five a really useful little thing that I actually just recently discovered if you're for example pinging a t-888 just for instance here and then you want to do some other stuff I mean that's often we're like exploring a host or we're kind of poking and prodding it and you're running nmap and you're running paying and you're trying to tell that to something and you may be doing and netcat or something who knows you're doing something repeatedly different things you've been you're doing a bunch of different things to kind of work on one resource like a host one of the things that's really useful is the alt period command and what that is is so I just ran ping and my argument was the IP address that I want to ping if I want to MTR this which is a much better trace route then I can just do MTR and then alt period and it will just give me the argument of my last successful command so MTR it God why is it damn it Ubuntu ruin even MTR curses I think yes so that actually needed another argument that's a terrible example but the point is alt period will just paste your previous commands argument once bonus round so I actually couldn't get my terminal screwed up enough occasionally like it will do this occasionally ssh logins that have gone bad and kind of disconnected and the pipes broken will do this but occasionally you'll get a terminal that's really screwed up a little bit you'll hit enter and it'll just print another one of these next to it on the same line and so you just kind of get moved over all the way to the right and things are just getting really wonky but you don't necessarily want to close your terminal one of the things you can do is type reset and that will kind of get things back to how they started it will people unborn to get borked this will probably work like ninety percent of the time again I noticed this myself especially with like remote shells virtual ends can do this if you're working in Python I'm assuming rubian anything that's like really messing with your terminal can cause these strange Bork situations and when you kind of don't know what to do and you're about to just like close the terminal and open a new tab or terminal session reset can save the day putting that in there as a bonus it's just a nice little thing to have in your tool then okay so those are the five things that I find myself using the most to get around the shell quickly and kind of be efficient get my work done fast there's definitely other ones like transposing lines or characters but these are the ones that I find myself actually using all day long that's been helpful if it has remember to subscribe and like notify even though that doesn't really work anymore you know pray to the YouTube gods that one day you might see another video of mine alright thanks again peace
Info
Channel: tutoriaLinux
Views: 576,386
Rating: 4.9515724 out of 5
Keywords: tutorial, system administration, sysadmin, command-line, CLI, linux, ubuntu, ubuntu terminal, linux terminal, linux terminal basics, bash speed, bash efficiency, bash shell, learn linux cli, learn bash
Id: V8EUdia_kOE
Channel Id: undefined
Length: 11min 6sec (666 seconds)
Published: Sun Jun 03 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.