 There's the idea that the command line is this big scary thing that you have to learn and be the master of if you're going to be a good Linux user, and for the most part that's complete and utter nonsense. The vast majority of Linux users can go their entire Linux careers if you want to call it that, without using the terminal more than a few times. I wouldn't say never use it because they probably will once in a while have to use it, but for the most part, everything you can do in the terminal can be done with a GUI of some kind. But for the people who enjoy using the terminal and want to learn how to use it, there are several really neat tricks that you can use to improve your efficiency and just do some really neat stuff. So today I'm going to be talking about ten tips and tricks that will help you become a much better terminal user. So let's go ahead and jump in. Okay, so here we are in the terminal. It doesn't really matter what terminal emulator you're using. So first of all, I guess I should define that term. So if you're a Linux noob or a terminal noob, a terminal emulator is basically what your shell runs in. And it's a translation layer, that's not really the right term, but it's a mechanism that will associate, that will translate between your shell and your terminal and the running kernel underneath. It's more technical than that, but just know that that's what a terminal is. It allows you to interact with your system through commands. So the first tip I'm going to give you is, while you're navigating through your file structure, there are ways to get back and forth from one place to another. So everyone knows the CD command. That's change directory. So let's just go ahead and change into my media directory and my documents directory. And we'll do an ls here. Let's say I wanted to go back to the last directory. In this case, it's the home directory, but we can change that. Let's go ahead and CD into pages. Okay, and we'll go into another directory. Let's say I wanted to go back to the directory above this. Now, there are several ways to do this. We could do CD dot dot, that would work. Or we could just do CD till the slash documents or media documents, that would work. That's a lot of typing, but theoretically you could do that if you wanted to do that. Or you could use this first tip and that's just do CD dash. And that takes you back to the last working directory. Now, it's not that impressive when it's just a directory up. So let's go ahead and go to CD slash Etsy and then SAMBA. Let's just say you're editing your SAMBA configuration file. And this is where you got to go. Now we're in Etsy SAMBA. Let's say we wanted to go back to documents. So we just do CD dash. There'd be no easy way of doing this. The only two ways I know of doing this would be to do CD till the slash media documents. So it had to go through in that way. But if we use our trick, just do CD dash, that takes us back to the documents folder. So what this does is it takes you back to the last working directory. And that's our first tip. So the next tip is a key binding that will allow you to search through your command history. Now, every terminal, no matter what shell it's running, whether it's bash, ZSH, fish, whatever, they all keep a record of the commands that you run. Some shells keep a history much longer than others. Some keep it for a shorter amount of time. It doesn't matter. They all do it. They all keep a history of your commands. And I'm running ZSH here. And let's say I wanted to search through a command. Now, I could just hit the up key. And that would cycle through my entire command line history, one at a time, just going up a list. And it goes back and back and back as far as the history goes. But let's say you don't want to have to go through and keep hitting the up key over and over and over again. Let's say you don't want to do that. If you use the key binding control R, you get this thing. And what this allows you to do is search through your command history. So I know I have a script called M-M-D-T-S. And I've ran that before, but it's been almost two weeks now because this is my Bash Challenge script. And I haven't ran it since the podcast was recorded. So it's way back in history. But I know it was there. So I can go through and search my command history using control R. That is all you have to do. And then you can just go through and do this. Now, obviously this command won't work because we're not in the right directory. But you can go through and search your command history in that way. So that's number two. So this next one is a little bit different depending on which shell you use. So I'm using ZSH, and this is going to work a little bit different in Bash than it does in ZSH. So just keep that in mind. If it doesn't do exactly how it does it for me, it might do it a little bit different for you. And I will try to explain that. So let's say you've made a mistake somewhere. So let's do sudo nano slash Etsy, or let's do user share, X sessions, and then DWM.desktop. Let's say I made a mistake somewhere way back here. It doesn't matter. I didn't make a mistake, but let's just say I did. If you're in Bash, you can delete from the cursor all the way to the end by hitting control U. Now, as you see, that doesn't work in ZSH. Control U deletes the whole damn line. Why they're different? I don't know, but they are different. So if you've made a mistake and you just want to delete the whole line without having to just hold the back space all the way to the back, hit control U, that will delete the whole line in ZSH. How it works in Bash, we can actually find out how it works in Bash. I can just go to Bash here and do the same thing, sudo nano slash Etsy. I did it again, user share, X sessions, and then we can go back here and do control U and see what it does. Yeah, that deletes from that line to the beginning. I said that wrong earlier. So control U deletes from that line to the beginning of the prompt. Now let's say you wanted to go the other direction. Control K will delete from the cursor to the end of the line. So control K. So we'll just do some random typing here and go back here. So if you're in Bash, control U goes from the cursor to the beginning of the line. Control K goes from the cursor to the end of the line. Like I said, it doesn't work the same in Bash. If we go back to ZSH here and do our same random typing and we do control U, obviously it will delete the whole thing. Now the control K works just fine. It's really weird why they changed it. I don't know. It's one of the stupidest things I've found in ZSH so far. I don't understand why they changed that one key binding. It doesn't make sense. But just keep in mind, depending on what shell you use, some of these are going to be a little bit different. So one of the great things about control U in ZSH though, if we just hit control U, let's say we wanted to do an update here. And we enter the password and I'm just typing random letters here. You've made a mistake somewhere in your password but you can't see it because it doesn't show up. If you hit control U in ZSH, it deletes the whole thing. So you can just start your password over instead of having to hold down the back space or hit the enter key and start over again. So that's the cool thing about control U, deleting the whole thing. But again, that only works in ZSH. You'd have to hit the home and then control U in order for control U to work in bash. So that is tip number three. So the next tip is a little bit different. So everybody knows pseudo bang bang. And basically what pseudo bang bang does is when I say bang bang, I mean two exclamation points. Basically what that does is allows you to input the last command that you ran. So in this case, the last command that I ran was LS. And basically what that will allow you to do is run pseudo on that command. Now obviously we don't need to run pseudo on that, but say you go through and do this, pacman dash s, firefox, and you hit enter, you can't do that without root. So if we do pseudo bang bang, that will fix the problem. We don't have to go through and retype the whole thing. Now, everybody knows pseudo bang bang. It's fun to say, right, pseudo bang bang is, you know, whatever. But everybody knows it. But there is another thing you can do with something similar. So let's just say we want to use the contents of the last command. Not the command itself, but the output. We can do that using bang dollar sign. Now let's go ahead and do something here. So let's do echo hello world. And what that does is it just echoes hello world. Now let's just say we wanted to input that into a file. It'd be very easy. I mean, we could just go through and do echo hello world again and then put that into hello world dot txt. We could do that. That's a lot of typing, even with autocomplete, you know? Or tab complete. We really don't need to do that. So if we just do echo and then bang dollar sign into text.txt, I mean, we just called that. As you can see, it autocompleted to the output of the last command. So this is good for if you want to take the output of, say, a less command or a cat or pretty much anything you want to give you an output of some kind, you can take that output that you've already run. The command's already done. And put it into a text file. You can put it into another command. You can put it into said. You can put it into whatever you want. It was really quite useful if you want to go through and use the contents of the last command. So I will just reiterate that so that you can see it again. So if we do bang dollar sign and then in bash, it may very well not expand for this. This is how ZSH works, but it should work the same. It just won't be as functional. It will look like bang dollar sign until you hit the enter key. So with ZSH, if you hit the space bar and then do whatever you want to do to it, it will actually expand it. But in bash, you'll probably just stay bang dollar sign until you hit the enter key. So just keep that in mind. But as you can see, that can be quite useful. Now the next one is something that I think everybody should do. So if you're familiar with an alias, you probably know how functional and awesome they can be. Now if you get to relying on aliases, you can obviously have a problem when you move to a different machine that doesn't have your bash or ZSHRC on it. But if you use aliases and I think everybody does, you can actually go through and create some aliases that will correct common typos. So I'm going to CD into my .config file ZSH file here. If we do an LSD, I have an aliases.text file. So this basically just allows me to source that file from my ZSHRC. You don't have to do it that way. A lot of people don't. They just put their aliases in their shellRC file. I happen to keep them separate. So I'm going to vim into aliases.txt. And as you can see here, this will allow you to fix obvious typos. So if I go through and let's just say I do a CD into .media again and I do CD period period, if I didn't have this alias, it would give me an error because there's no space here. You have to have a space here in order for CD period period to work. And basically what that does is it takes you up a level. But if you don't have the space, it won't work. But because I have an alias, it will still work, even though it's a typo. I have several things for if I am typing too fast. So if I try to print the working directory, and that's normally PWD, and it works just fine. But if I do PWD, PDW, which I'm prone to do, this will actually work because I have an alias for it, even though it was spelled incorrectly. So you can do these things for like your Pac-Man. If you say you spell Pac-Man's PCA, and then you could go through and create an alias for that to actually correct itself to Pac-Man or apt or whatever you want to do. Just create a few aliases for things that you misspell constantly. Not necessarily that you don't know how to spell them. Because you're going fast or whatever, you make a mistake. And this way, if you made a mistake and you have an alias to save your ass, you don't have to go through and retype the command or rerun the command. So that's a great use of aliases. Now there's obviously a whole bunch of other things you can do with aliases as well, but we won't go through those today. That's the topic for another video. Now let's go ahead and close this. And we'll move on to the next one. So the next one is kind of cool. Now it has limited utility because most commands that require user input during their execution usually have this built in. So for example, if you're on Ubuntu, you need to sudo apt, I can't type, apt install firefox again, whatever. And then you can do this, do dash dash no dash confirm, I think is the way you would do it. And I think it's the same way in Pacman as well. That basically what this will do is go through and run this command without you having to go through and hit the yes, the Y key in order to confirm that you want it to actually install firefox or do an update or whatever. Most commands that require you to have this input have an option for you to bypass it. But let's just say it doesn't have an option to bypass it. So let's just say apt didn't have that or maybe you didn't remember what the flag was. It's possible that I have the flag wrong. I don't use Ubuntu. But what you could do is use yes command. So if you do yes and then the pipe, which is directly above the enter key, at least on my keyboard, and then you run this command on Ubuntu obviously, it would go through and do the exact same thing as no confirm would do. Just go through and bypass any user input and just install firefox. Same thing if you're going through and running an update. So let's just do this. Let's just say I do sudo pacman dash s s s y y u. Let's just say I do that. And I hit the enter key and enter my password. And then it's gonna ask me, are you sure you wanna update? And I would have to go through and hit yes. I actually have to stay here in front of the computer in order for that to happen. But let's just say pacman didn't have an option to bypass that, which it does, but let's just say it didn't. We could do yes pipe into that and it would actually go through and do an update that way. Now I'm not gonna do an update on camera because things crash and stuff. I don't wanna risk the recording because we're this far and I don't want to start over. But you could do that. So that is the yes command. Really cool for scripts or something that you want to have the necessity of user input. Yes or no, and you don't wanna have to sit there in front of it and watch for that prompt to come up. The next one is to allow you to move back and forth between words. So let's say we have some words here. There's random words with a command. And let's just say we wanted to move back and forth between these commands. So alt F and alt B move back and forth between commands. So alt B moves backwards in a command. Alt F moves forward word by word in a command. So let's just say we made a mistake in this gibberish in this one here. We could go back to this one and just delete this one word and then retype it, correcting our mistake. And then we can just go back forward to commands and go to the end of the line or we can hit the N key in order to get back to the end of the line. So that's how you move back and forth between words in a command. So if you have like a gigantic one liner in bash or ZSH and you've made a mistake smack dab in the middle, you can just go through and do alt B in order to get back to it, make your change and then hit N key to go back to the end. Or you can go line by line using alt F. Now, let's just say we've gone backwards a couple lines here and say we're here and we've made a mistake in the word preceding this one. If we do alt backspace, that deletes the word prior to the cursor. So when you use your alt F and alt B, if you stop one word too soon and then you use alt backspace, that will delete the word directly in front of the cursor. And that's really good for when you make a mistake and you want to delete the whole word. And obviously you could just use the backspace to delete the whole word that way, but this is easier. So alt F, alt B moves forwards and backwards between words, alt backspace will delete previous words. And I believe that work is exactly the same way in bash. So the next one is really important. So if you do shutdown dash C, so if this is how you shut down your computer and you hit enter, and I'm gonna do this on camera, so this damn well better work and hit enter, it's going to schedule your shutdown for the next minute. Let's just say you need to go through and change that. You want to get out of that. So if you do pkill shutdown and do this, it kills the shutdown. All right, that means it shouldn't shut down in a minute, hopefully. If it does shut down, we're screwed. And I'll have to start over again, that would suck. But that should go through and kill the shutdown process so that doesn't actually shut down. So this is good for, let's say you've scheduled your shutdown for a minute from now, using shutdown dash C. And you suddenly realize, oh shit, I haven't saved my work. You can kill shutdown using this command and go save your work and then just reschedule it. Now, this doesn't work obviously if you do shutdown now because that shuts down your computer right now. That's not a great thing, right? So you definitely want to make sure you save your work if you're gonna use shutdown now. I believe in Bash that it will actually give you some output. Why doesn't do that in ZSH? And it's giving me an error code, it's kind of freaking me out right now. So if you see a time jump right here, you'll know my computer shut down. And this command doesn't in fact work in ZSH. I'm kind of waiting for a minute to make sure that it doesn't shut my computer down because that would suck. Okay, so the next tip that I want to give you is to how to purify some output. And what I mean by this is just that sometimes you have a long list of output when you run a command. So let me cat a file I have called weather. And basically what this does is it keeps the last 50 inputs of my weather script. And the weather script is then put through tail and that goes into my bar at the top so that I only have the one bar and it always has the most recent. It allows me to control the number of times the weather script updates because SL status goes through and updates every nanosecond or something. It's really ridiculous. And I don't want the weather to update that much. So I use a cron job to run this script which puts it into a file and then it does that every hour and then the script can get it however often it wants but it was not gonna update the script every nanosecond or whatever. So if I cat this out I have just a gigantic list of temperatures. It's not a ton. It was a ton before I rewrote the script to actually get rid of quite a few. It just kept them forever and ever. I believe I had the same thing when I had a temperature script up here for the CPU. I let it keep it forever and ever and ended up having a 12 gigabyte file because it literally ran it every three minutes and I kept that output forever. It was ridiculous. So I did the same thing with the weather. So this used to be a lot longer but it's still not pretty. So let's say we cat this into an application called column if I can spell it right. C-O-L-U-M-N. Now if this works correctly we should see it a little bit prettier and we do. That's what column does. It takes the output of a command and splits it into columns. Now there are a few things you can do with columns. You can control the number of columns it shows you. You can control what the separator for the columns are if we want to make it even prettier. If you want to find out more just do man column and it will tell you a whole bunch of stuff you can do with it. If you want you can do the output width, table headings, output separator, separator table, table columns and so on and so forth. It's a very really neat program that will allow you to go through and make an output of a command prettier. So this is not necessarily all that useful on the command line unless you want them just, you're very worried about aesthetics and can't scroll for some reason. But if you use this in a bash script for an output where you're a little bit more worried about how the output looks this could be really very powerful. Now you can do this in pure bash. You can do it in pure bash. I don't know how. I probably would never learn how because column just does the job. So that is column. All right, the last command and we've now bypassed a minute so my computer's not gonna shut down. Thanks goodness. The last thing I want to talk to you about today in terms of tips and tricks is how to bypass your shell history. So let's say you're running a script or something that you don't want to appear in your history for someone else. It's a great gag gift. If you wanted to pull a prank on someone I suppose you could do it this way but it's also for security reasons you could run it. Please don't go run commands in other people's systems. Don't do that. Don't be an asshole. I would definitely do that though. I'm an asshole. I can't help it. Anyways, let's just say for whatever reason you're running some kind of program or you're putting some kind of input into the command line that's sensitive and you don't want it to be stored forever in your BASH history or your ZSH history. You can do that very easily. You can bypass the history very easily by just putting a space between it. So if I do space CD and then I go up a level it actually does keep it there. So maybe that doesn't work in BASH or in ZSH. Let's go to BASH and find out. I actually didn't test that. So let's just say we'll CD into document downloads and then we'll do space CD, go back. And if I scroll up one, yes. It works in BASH, doesn't work in ZSH. I'm glad I tested that out beforehand, dumbass. Anyways, in BASH it'll bypass your BASH history. So technically my last command was just CD but if we scroll up it just CDs downloads which is the command before that. So if you need to bypass your history in BASH this is a way to do it. Just leave a space before you do the command. So that is it. Those are the tips and tricks that I have compiled for you to make your life in the command line easier and prettier and more awesome. Now there are just a ton more where this came from and if you're interested in seeing more tips and tricks like this leave a comment in the comment section below leave a like, all that kind of stuff and make sure you're subscribed because I will do it if it's popular enough and people want it. So definitely do that. So if you have a cool command leave it in the comments below I'd like to see it, maybe we can feature it in another video. If you want to get in contact with me you can do so at the Linuxcast. You can support me on Patreon at patreon.com slash linuxcast. Before I go I'd like to take a moment to thank my current patrons. Devon, Chris, East Coast Web Gen 2 is fun too. Marcus, Megalyn, Donnie, Sven, Jackson, Knife and Tool, Mitchell, Mr. Fox Arts Center, American Camp. Thanks everybody for watching. I'll see you next time.