Saving Time At The Command Line

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the command line many Linux users fear the command line for some reason I assume it's because they just haven't had the experience with the command line all they know is they're familiar graphical user interfaces but when you can learn the command line when you can harness and leverage the power of the command line you can do some amazing things in Linux but to increase your speed and productivity at the command line there are some tips and tricks you really need to know to be able to get the most out of the command line so today I'm going to share with you some tips and tricks that will save you time when you're at the command line let's get started so the first thing I need to do of course is pull up a terminal for this demonstration so I think most shell users know about the history command I'm gonna show you the history command not because this is what I wanted to cover but I wanted to make a point with this so this is your shells history all the commands I've run recently let me just pick one in my shells history number 1535 here is a CH top so to run that typically to run something from your history you do the exclamation point and then the number 1535 and you see I get some output in the terminal type appears do I really want to run that hit enter if that's what I want to run or control see if I don't want to run it so that is you know the basics of the history command but a lot of people don't know there's more you can do with the exclamation point than just exclamation point and then a number from your shells history for example did you know that you can do exclamation point followed by a command any command and it will run that command the exact same way you ran it the last time you're in it for example if I did a exclamation point LS it's gonna run the LS command with all the flags that I gave it the last time I ran the LS command I don't know what I ran last time it looks like I ran LS space dash lah capital D so that is a pretty neat and that works with pretty much any command what if for example I wanted to run them the exact same way I ran them the last time which means it's going to open up film a document and film that I opened up last time again I don't know what I did last time in film but if I did exclamation point mil and hit enter it looks like I was editing my awesome window manager config file the RC Lua file so if I just hit enter right now it would open up my RC Lua file and boom really need to edit that so that is a command a lot of new Linux users a lot of new to the command line users don't know about it's just exclamation point followed by the name of a command and it will run that same command that you did last time so if I did exclamation point CD I don't know if I actually see to eat into a different directory and I specified a specific directory but if I did you know well apparently I did so it would seem again to that directory that I see deed into the last time I ran that come in the other thing you should know about is the two exclamation points in a row so what if I ran this command pac-man - capital s lower case Y lower case you an arch that updates my system ah I cannot perform this operation because I am NOT root duh so how do I perform this as root well the easy way to do this is to type the word sudo of course and then pac-man - syu but you know what the last command that you ran and the shield is two exclamation points in a row so sudo space exclamation point exclamation point hit Enter there we go is that really what I want to run nope I don't need to update my system here on camera but that saves you a ton of time because how many times have you typed this very long and tedious and convoluted command hit Enter boom you didn't give it root privileges and now you have to go back and sudo and then type that very long command no you don't have to do that sudo space exclamation point exclamation point and you're done another neat trick with your shell is ctrl R type ctrl R and look I've got back I search now what exactly is this well it's going to search through your coming you're history basically so what if I wanted to search through my history for the last time I had the word installed as part as a command looks like I ran sudo pip install uber Zug and that was months ago but they're ephemeris that I get hit enter right now if I really wanted to to run that command it's gonna ask me for my root password so let me cancel that again just for a demonstration control or once again and you know him and it remembers the last time I ran VM which of course was just a few seconds ago vim and then my RC Lua file ctrl C to cancel that so that is ctrl R now what if you want to run multiple commands like two or three or even four commands at a time typically you probably think well I got to run one command and then run the next then run the next well no you don't have to do that you can string these commands together all in one line so how would you do that well an example would be take your Debian or a balloon tube based systems I'm not on Debian or Ubuntu today but how do you update your system well if you do it at the command line you do sudo apt update you run that and then you run sudo apt upgrade at two different commands what if you wanted to do them all at the same time well you would simply string them together like this sudo apt update semicolon space sudo apt upgrade and it would run the update then it would run the upgrade this also works when you're stringing together two commands sudo apt update and and two ampere signs and then sudo apt upgrade either one of those works so I can't run that command to show you that in action because again I'm not on Debian or a bun too so let's do something else why don't I run the LS command and then semicolon and then CD into a different directory how about root just for something you know silly to run and there first of all it ran in the CD or the LS command in my home directory and then it changed me to the root directory so it ran both commands so I didn't have to you know CD and then LS or LS and then CD and just run them all at one time if I wanted to do it with the two ampere symbol let's do that one more time Ellis and then and ant and then CD back into home so no other arguments CD will just take us back to home run that it ran the LS on my root folder because I was already there and then it's Eid Eid me back into my home directory so that is how you put together multiple commands at the command line one of the things that you often do at the command line is getting a file catting a file so it spits out the output in the terminal for you to read now that's great if the file is not very long but if it's a really long file it can cause you some problems for example I'm gonna run my last command main leak just so I can get this document name because I know this is a long document now if I wanted to I could cat this document so assume this is like some system config file not just my awesome config maybe I'm kidding I don't know something in the slash Etsy folder and I cat it well it's a very lengthy document now I have to scroll back up through the document to try to find and it takes me to the very end cat you always get to the very end and you're at the prompt again so it doesn't even start you at the top of the document this is a bit tedious so what I would do is if I actually want to start at the top and read a document don't use kit use lists so less and then space name of document and now you're at the top of the document and with the Enter key you can scroll through the document at your leisure and hopefully find what you're looking for now one other neat thing you can do with getting a file that makes things easier if it's a very lengthy file which this one is you can cat name up a file and then the pipe symbol and then use the grip tool to sir if you know exactly what you're searching for for example I know there's a line in my awesome config file or a key binding for erssime I iirc check lance so if I grip space I RSSI and hit enter it's going to cat my awesome config and then it's gonna grip out the lines that contain the word RC I hit enter there you go apparently there are two lines in the config file that contained the word irsie and it catted them out that way I don't have to read that massive config file you know I knew exactly what I was looking for instead of me opening it and then doing a search with less or even opening it and them and doing a search in vim well if I know exactly what I'm looking for cut it out pipe symbol grip what you're looking for boom Bob's your uncle now that command I just ran with cat and then using the pipe symbol and grip to grab a search term that is something thousands maybe millions of command-line users typically do is use cat and grip in combination but you don't actually have to do that you can use grip by itself you don't even need cat so if I go back to that last command I just ran and I'm going to take the file name but I'm gonna get rid of cat and instead I'm going to grip and then in quotes I'm going to do a search term how about Percy once again in quote and then the name of the file if I do that I get the same thing so I don't even have to invoke cat I don't have to cat and then pipe it into grip know that there's no reason to even involve cat even though like I said most command line users probably do cat and then pipe symbol grip no you don't have to do that just if you know what you're looking for grip followed by the search term followed by the file you're searching in and the last tip I'm gonna leave you with on this video is if you really want to be quicker at the command line to be faster and more productive obviously you have to practice you have to practice doing stuff at the command line and you have to practice you have to learn these commands write it when you come across a command at the command line you don't know anything about it read up on it that that's what I try to do spend a little time with it that way the next time you come across it you know I remember what that command does so when you come across something like the find command for example read the man page every program just about every program out there should have a man page so type man for manual space and then the name of the command man find is me the man page for the find command now this is a gigantic man page because find is a very powerful program I'm gonna quit out of that but what you could do is you could install a easier to reads man page alternative like TL DR is one I quite like TL DR space fine and this gives you a much easier to read man page it gives you real world examples of how to use the fine command fine files by extension and here's the command as an example fine files by matching multiple patterns and here's the example command to run so TL DR is great I suggest installing something like TL DR or maybe cheat sheets as a man page alternative but just reading the man page is a good idea but spend time learn more commands learn more flags with the commands you already know so we were doing some stuff with LS earlier do you know all the commands with LS well why don't you man LS and see all the flags that you can use with the LS command that you're probably not using also when you figure out that you like to use something like LS base - lah as your default LS command well instead of having to type that every time why don't you create a bash alias right why don't you you know open up your bash RC file assuming you're using bash and in here why don't you put a alias where my aliases well I've got a few at the bottom here here is my LS alias so I have LS Elias - LS space - - color equals Auto but what if I wanted to change that and actually I kind of do want to change that I don't use bash I'm in Arco Linux and Arco like most Arch Linux distributions uses zsh by default so I've been using zsh a lot here lately but what if I want my default LS command to always be l ah4 the flags so I just changed that now all I need to do is escape write quit and now when I run LS every time I run LS it'll be LS - lah before I go I need to think a few special people this show was made possible by handsome first Chris 2nd Chris Dylan George Mitchell Nate Eck Philip Rob Robert salmon Willie the producers of the show they're my highest tiered patrons over on patreon without these guys this show about saving time at the command-line would been possible this show was also brought to you by all those fine ladies and gentlemen all those names you see on the screen that ever-growing list of names that help support my work over on patreon again without each and every one of those ladies and gentlemen this show wouldn't be possible less sincere thank you to those guys if you'd like to support the channel please consider doing so go find me at distro tube over on patreon alright guys peace [Music]
Info
Channel: DistroTube
Views: 73,889
Rating: undefined out of 5
Keywords: command line, terminal, Linux, shell, bash, zsh, history, sudo, cat, less, grep, man, tldr, alias, command line basics, command line tutorial, command line linux, bash shell commands
Id: Y_6C-jowk8o
Channel Id: undefined
Length: 13min 49sec (829 seconds)
Published: Mon Aug 19 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.