 We're gonna learn in this video all the basics about using a terminal in either Linux or Mac OS same principle a lot of people will call it the terminal a lot of people will call it bash or the command line technically all those are Different things. I will talk about that But I'm assuming that you're turning on this video. You don't know anything about the command line You don't know anything about bash. You just think it's a big black scary box And you're you think you're it's for hackers or something like that. It's actually very easy So let's talk about some basic commands. So first off when you open up your Terminal you'll have something like this. You'll have some kind of prompt and you can type commands on it So let's actually first find out where we are If you want to find out where you are you can type in PWD that means print working directory now Of course a terminal instance is just like the instance of a file manager In that a file manager might have a particular directory open. It's the same principle here We're actually in this directory slash home slash Luke You're gonna be in slash home slash your name. This is your home directory. That's where you're gonna start It's you know the place you've start out basically So PWD shows you where you are another basic command is LS. So LS will show you what's around you Okay, LS says okay. Show me all the files in this directory Files and directories. So for example here I have you'll see in blue. I have docs pick Vids work. Those are all directories. I also have some files here I have this screencast file, which I'm actually currently recorded recording and I have some other files as well that you know Just happened to be in my home directory as I started this Okay, so LS is one of the most basic commands now one of the most important commands actually the most important command The command to rule them all is the command man. This is the most important thing to learn from this You know this video already We're gonna learn a lot of a lot of important things but remember man man Tells you anything you want to know about another command. So let's say we want to learn about LS We type in man LS and boom we actually get LS is in all of its instructions All of you know, it's whole manual so to speak now It's not like a whole book, but it's a page here You can scroll up and down with either arrow keys or Vim keys. That's J and K so you can scroll up and down You can look at all the options they have and this basically tells you all the The extra features of LS all the kind of things that it can do And if you want to quit out of this, you can just press Q. Okay, so let's actually let's look at this manual briefly Oh, actually see what I just did. Here's one other thing about the command line is that there are a lot of different Little shortcuts to do things. So let's say I want to rerun this command a man LS Well in order I could re type it out, but especially if you have a long command That's sort of hard. So you can actually just press the up arrow and when you press the up arrow You scroll through previous commands. See how I'm scrolling through them or you can scroll down to go downwards Either way, I'm gonna press man LS. Let's look at Some of the options here. So for example a this is one of the most common options to LS That says do not ignore entries starting with dot. Okay, what is that? Let's try and let's see what goes on here So if I type LS with the a option or a tag or a switch people call them different things It will actually show me a whole bunch more content. What's going on here? Well, what's going on here is if you just run LS It shows you Sort of the default files in this directory But if you run LS with the a option it actually shows you all the hidden files as well now these hidden files They're not like, you know secret or encrypted or something like that They're really just stuff that your operating system has to store in your home directory But it doesn't want them to always be visible. I mean like your config folder, for example It has a lot of important information And as you learn to use the command line and stuff like that, you'll realize a bunch of programs can be modified in there It's very handy But you don't always want to see this config folder So the convention is on Unix based operating systems like Linux and mac os you put a dot in front of files That you want to be hidden and LS and other command or other Programs as well will ignore it won't show by default things with a dot in front of them But if you run it with the a option it shows that stuff with a dot on it now notice also right now My screen is full at any point in time if you want to clear your screen You can hold down control and press L and most Interpreters will will clear the screen with that You could also run the command clear that will work pretty much all the time You know sometimes control L won't work on certain systems. They don't have it configured But either way control l 99% of the time it works some servers might not have it but anyway, so LS LSA we know how to clear the screen with control L. We know how to go up and down through command history We know pre PWD to print our working directory. So what other stuff can we do? Well, here's another option for LS you can learn this in man in man LS if you'd like But another option is LS with the L option This actually prints out all the the folders in this directory Or folders and file and files in this directory. It has its their names over here. It has the date They've been modified. It has their size. It has the owner. It has these things on the left here are file permissions So there are a bunch of different options you can run LS with again You can check man LS for all of them and they they give you a lot of granulated control over the things you're doing, right? Additionally, you could run it with the a option and the L option at the same time Now you might want to do something like this that that would actually work But you can also just do this, you know LS LNA and this will print out It will run the a option showing all the hidden files see we have these hidden files with dot But it all also will show this expanded information. Okay. All right, so that's that's about enough for LS right now I'm gonna control L to clear the screen actually. Let's look at our folders here. Let's talk about moving to different directories Now how you move to different directories is with the command CD and that stands for change directory Let's say I want to move to this work directory Then I type in CD and then work. Okay now I'm in this work directory now notice in my case This might happen on your machine as well my prompt has changed instead of having this tilde at the beginning which indicates, you know The home directory it's an abbreviation for slash home slash Luke on my machine It now says work because that's the current directory. I'm in we can also run PWD and see oh, yes We are indeed in work. There is the full path of our location Now in work we can also run LS and we'll see all of the files in this directory Now if we want to change let's say I want to go back to the home directory We can actually just type CD and any point in time without putting a directory name and it will return us to our home directory Or let's say something different. Well, actually, I should be clear So LS we talked about LS shows the directory contents But you don't actually have to be in that directory to run LS on it For example, I'm in my home directory. I'm gonna clear the screen. So I'm in my home directory This is what it looks like. I can also just run LS on the work folder. Okay, so if I run that it will show me What's in the work folder? I don't actually have to change directories to do that But of course I can if I want I'm gonna change directories to the work folder Actually, I did another very useful little thing here and this is one of the most important things You know, let's say you don't want to type things out on the command line all the time Well, luckily if I just type W here, okay And then what I do is I press tab and what tab does at any point in time is your command interpreter Your you know your interpreter will say, okay, he pressed tab Let me just guess what he's trying to type and in this case since we're in a directory where there's only one thing That starts with W. It's gonna know. Oh, he wants to go to the work folder. So I'll fill that in for him So you'll see me doing that a lot. That's a very important trick. Okay, so now we're in the work directory here I'm gonna look at the contents here. Actually, let's go let's go into one of these other directories. Maybe this one in R, okay, and I can see the contents of that as well if I wanted to with LS, okay Now another thing that you can do in any point in time So we talked about if you you can run CD on a directory you can also Just type CD and you'll return to your home directory, but you you also have what are called relative paths So I'm gonna clear the screen again and let me run the command LS with the a option Okay, so we see those two directories that you just saw when I ran LS before but you also see these other two things What are those these are not traditional? Directories or files in the way that you might think of but there are sort of abbreviations Well, they kind of are directories, but really what dot dot means dot dot means the directory Directly above us. So if you remember we were in our home directory, actually let me type PWD We were in our home directory. We cd'd into our work directory Then we cd'd into this in our directory now at wherever you are dot dot refers to the directory Over you. Okay, and what that means is I can do this. Let's say I want to go back to the work Directory well, I could type out something like this home Luke work that would actually work But what you can also do is just type dot dot and that means go to the directory right above me or if I'm in this work Directory and I run cd dot dot again. I'm actually gonna be in the home directory So now here I am or really slash home slash Luke my home directory or if I type cd dot dot again I'm gonna be PWD. I'm gonna be in the slash home That is the the slash home directory where all the individual home directories including mine are stored Okay, and at any point in time you can type cd and you'll return home Okay, so that's that's how you navigate around so cd changes your directory LS shows you the directory Contents and for any of these you can type man and the command name and it should give you information Actually, I don't know if cd has a man. Yes, it does have a man. It's very simple though Anyway, you can check it out So another an important command or another thing you might want to do is move files around. Okay, so let's let's Let's start playing around with this Actually, I'm going to I'm gonna move to my picks directory I'm gonna say picks and you can also you don't have to change one directory at a time You could actually let's say I'm gonna cd to picks and then I'm gonna press tab and it's gonna show me if you double Press tab twice. It's gonna show me a list of all of these directories in here So let's say I want to go to my wallpapers folder and in there I can press tab twice and it's gonna give me a list of the different directories in here I'll say the landscapes folder or something like that. Okay, PWD. There's where we are So I'm gonna show that I'm gonna press LS to see all the contents in there And I actually have a lot of files in here. Okay, let's say I want to copy some of these files to my home directory Okay, let's say I'll take this very last one here If I want to copy that one to my home directory, you use the command cp for copy. Okay, so cp Then I'm gonna start typing in this director or this file name So it starts with zh and it of course, it's hard to type look at all the typing I have to do Well, I can just press tab at any point and it's gonna guess what the rest of that's gonna be And if I want to move it to my home directory, I noted this before I'm gonna clear the screen for a second But if I want to move it to my home directory, I noted that the tilde I said this earlier the tilde always refers to home. Okay Now if you want to move it home, you can just say you could type out home Luke But that's a little hard because tilde is always gonna be an abbreviation for that So I'm gonna run that now nothing seemed to have happened it and say, okay I moved this file or anything like that But it actually worked Usually on the command line if you don't see it like any feedback from a command. That's a good sign If something goes wrong, it's gonna say that it went wrong So if I run LS on my home directory, you'll see in here that this file now is there. Okay, great Now let's move. Let's move another command back I'm gonna run clear just cuz I don't know pressing control L over and over again Just seems redundant. So I'll type it in. So here's We can also Move multiple files at the same time or copy multiple files at the same same time I should say we haven't talked about moving yet, but it's the same principle Let's say I want to move these other two I'll move Yamagata and Windows bliss to the home directory. Well, I can actually just type them both in so I pressed Double or YA and then press tab and I'll start typing this one and press tab And then I will move them to the home direct or copy them to the home directory. I keep saying move So now let's actually go back to my home directory just by typing CD Look at the contents and you'll see that we have Windows bliss. We have Yamagata. We have Janya, Dancia All of these files are now in our home directory So let's let's do so we've copied these over. What else can we do now? Here's a nice little thing. I'm actually going to create a new directory Let's say I want to move these three files to a new directory. So I'm gonna run the the command mkdir Okay, so mkdir just means make directory. So I'm gonna call it new deer, okay And now I am going to copy. Let's say I copy. Well, here's what I'm gonna run Or actually no, I won't do copying. I'll move them. Okay, so to move stuff you use MV Okay, so I can run it on one of these individual files. It actually works just like copy Except for you're not making a copy or just moving it you can move it to new directory Okay, and again, it will show nothing But I'm gonna clear the screen if I type LS you'll see that the file is no longer there And if I run LS on this new directory, you will see that it's now there That is one way to move these files and we could run move on each of these JPEG files individually But there's a quicker way to do that. We could do this we can say MV star JPEG and then the directory we want to move them to okay now what is going on here now first off I'll just run it to show you that it works Okay, and you'll see that now we we do not have any of these JPEG files in our home directory And we do have them in this new directory. Okay, so what's going on here? When you run this command here, and this is not just with move. This is with copy. This is even with LS what this asterisk mean what this what the star means is Any file any sequence of characters? Okay, it stands for any sequence of characters and then I have JPEG at the end and that really means move all the files That start to have anything as long as it ends with JPEG That is really all the files that end with JPEG move them to the new directory Okay, that's what that means and of course you can run it with any other command as well Let's actually move to this new directory here. Okay, let's say I'm inside of this new directory I'm gonna make it yet another directory, so I'll say another directory again in KDIR makes a directory Now we see that we have these three files and our new directory and let's say I want to copy all these files in well I can say copy JPEG And then I can move them to another deer and it's going to move them there. Okay, or Copy copy them there. So we have them in here now. We have them in another directory. Okay, and this is not actually just with Just with files that happen to have the same extension. Okay, let's for example, just I'm gonna make yet another example directory Okay, so here's here's an example here I'm gonna create a file and there are different ways to create a file Usually the one that people use is touch and I'm gonna touch a file and I'm gonna call it, you know Yo or something like that. I don't know you so I don't know it doesn't matter. I just want it to start with y Okay, so now what I'm going to do is just to be clear So another that I was another deer the one I just made or example. Okay. Yeah examples the one I just made Okay, so now what I want to do is I want to move the Yamagata file and the you file Into the example directory we can do that by saying move and then why because they both start with y and then The the glob matcher the asterisk the the the wild card to say Basically what we're saying is move everything that starts with a y and then has any sequence of characters move that to example That's what that means. So if we LS an example You will now see that those two files are here and since we move them They're no longer in the directory that we are now in okay So that's how you move files and not just move files But you can specify to the command line very specific things, you know, I want to move I want to delete all the JPEG files. I want to move all the PNG files. I want to Copy all the text files. It's very easy on the command line to specify something like that Whereas in a graphical file manager, you might have to be like, okay Click on these couple of options and say, oh, yeah, select these extensions or you know, there's a regular expression It's a it's a little bit more difficult and actually these kind of pattern matching sequences The most basic one is the asterisk which really just means anything But there are other ones as well. So to be clear Let me cd into the example directory now if I want to delete a file The command you use for that is RM or really remove is the mnemonic And to be clear just to remind you I got to remind you because why not this command man is still the most important command What does it do? It gives you a manual. It works on LS. It works on CP. We can learn about copying stuff We can learn about all the different options. For example, here's here's an option that might be important F if we copy something with the F option. Oh, well by default It will not it will not overwrite a file if it's already on the the place You're moving it to or copying it to but if you give it F it actually will do that. Okay So anyway So you can check so check the manual for all of these commands for different options you can do But anyway, what was I what what did I just say I was going to do? Oh, yeah, removing stuff Okay, so to remove stuff you use the RM command. Okay. Now. I should say the RM command can be a little bit Dangerous, I mean, it's not really dangerous once you know how to use it But to be clear when you delete something on the command line, it's deleted from your operating system It's not it doesn't go to a recycling bin or something silly like that when you say you want to delete something It's gone now technically depending on your file system. You can recover files and stuff like that But that is not something within your operating system So anyway, our M delete stuff So let's say I want to delete this file you Okay, and that was just an empty file. I created with the touch command Oh, actually, you know just to remind you I think I mentioned it. I didn't really talk about it So the touch command makes files. So if I say touch files that Creates a file named files. It doesn't put anything in those files by default Now really what the touch command is supposed to do is that it updates the Modification date or the access date of a file that it's being run on But if you're running it on something that is not a file It will just create a blank file there. So a lot of people use touch to create create stuff. So anyway You can run our M on a file and it will delete it. Okay Additionally, even though I delete it. I'm gonna make yet another file Just to show you one more thing. So another file. So now we have two files in this directory If you just run this our M and then the asterisk now, this is a dangerous command at this point Now remember that asterisk means You know any sequence. So if I ran RM asterisk jpeg that means delete all the files in this directory that end with jpeg or if I run You know, let's say new Asterisk remove new asterisk that means delete all the files that start with new and then have any sequence after them Could have any extension could have other stuff in their file names doesn't matter Okay, but if I just run remove and then the asterisk sign that means delete all the files in this directory Okay, so if I run that again, it doesn't show you Output when it runs, but you can see that there's no longer anything in this directory Okay, so all this stuff has been removed from the example directory So I'm gonna go back here to new directory. I forget where we even are. Okay. Yeah I just I've just been making directories inside of each other. So now here we are so we know that RM deletes Deletes files. Okay. So for example in our current directory, there's this file You know Windows bliss if I want to get rid of it. I can run remove on that. Okay Now let's say, you know, I just cleared out all those files from the example directory Okay, and just to be sure if I run LS on example, there's nothing in there So let's say I want to get rid of the example directory now. You might be tempted. Okay I'm just gonna run remove on that and if you do it's gonna say no no no RM We don't like removing directories and that's for safety's sake. Okay, and that's actually a nice thing too Because just to be clear that's good because let's say you're in this directory and you accidentally run something like this RM star you might think That that that's gonna. Oh, no. I just deleted everything in this directory. That's bad. In fact, let's run it here Okay, it's actually gonna give you some errors now It will delete this file. Okay, it will delete files, but by default RM does not delete directories That's for safety's sake partially. Now the proper way to delete a directory is RM Deer. Okay So I'm gonna run RM Deer on example. It doesn't show anything. Let's run LS and we'll see. Okay, great It's been deleted. Okay Now let's run RM Deer on this other directory And it's gonna say something else It's gonna say fail to remove another Deer directory not empty Now the thing about RM Deer is it only runs on directories again This is safety like there's so much safety built into these commands But RM Deer only deletes a directory if it has nothing in it and another Deer if you remember We actually copied all of those images to it. Okay. Now there are two things you could do here One is you could physically remove all the files inside of it And then you run RM Deer on it, but that you know, sometimes you just want to delete something So you actually run RM with the special option actually before that let's say hypothetically Let me look at the contents of my home directory. Okay, let's say I might you know Still be using these jpeg files for something later in this little tutorial, so I'm gonna copy the Files in this directory. Okay, so now what I'm gonna do I'm in new directory and I'm gonna say copy the stuff in another directory Which is inside the directory we're currently in and I put the start the end which this is basically gonna say all The files in here copy them to my home directory. Okay, so now I've done that you'll see that since I copy them They're still in this directory and now they are also in my home directory. There are copies of them But anyway, if we actually want to delete this directory, which has stuff in it, you cannot run remove You cannot run remove Deer So what you do is something you could find out by running man RM. There is an option to RM that is R and that means remove directories and their content contents recursively. Okay, so What that means is actually I want to show you one more thing is what I'm gonna do another thing I know it sounds like I'm doing all these weird things. I'm gonna make a copy of this folder or actually oops I meant to do this Actually learning moments. So let's say I want to make a copy of a directory, okay? So I copy this directory and I'm gonna make a copy of it called copy by default Copy only works on individual files, but you can specify this option or Which recursively copies it meaning it copies not just the directory, but everything inside of it So you do in fact have a copy, you know, we now have two directories in their copies of each other All right, so to delete so R means recursive and copy it also means recursive in remove So if you actually want to delete a directory and all the things inside of it, which again may be dangerous You run RM with the R option. So if I run that oh, oh, I forgot about this Okay, so if you run this by default it will delete it without giving you a prompt Okay, so I have this thing it it came up and said oh, are you sure you want to delete this? Okay? That is because I forgot before this video. I had a little alias file now by default this thing will not come up but one thing about RM is It has some safety features built into it. Okay, one of them or two of them is this So let's say you accidentally run RM with the recursive option on a directory you didn't mean to well It's nice To also run it with these options. For example, I says, you know, whenever you try and You know, you know, you run you're running remove on multiple files It will prompt you are you sure you want to delete this? Are you sure you want to delete this? Capitalize the same thing it doesn't ask you for every every file But you know every couple of files or every directory or something like that and before I started this video But this is actually an important learning moment. Here's the thing. Okay, here's the hypothetical Let's say you are afraid of running Remove or any other command with some option that might cause damage to your system Okay, one thing that you can do is that you can modify a file called your bash RC Assuming that you're running bash if you don't know what you're running you're probably running bash Okay. Now, let's talk about this. I'm gonna go to my home directory Now I am going to open with nano begrudgingly I'm gonna open a file called bash RC, and I think I deleted this before I started the video So there shouldn't be any content in it, but let's say Hypothetically that we want a safer version. We want to only use the remove command When whenever we run it, we want it to have that option that capital I option to ask to prompt you if you really Want to delete something well in our bash RC file we can run this command alias RM equals RM With the capital I option and what this means is every time that I run RM I want you to interpret that I want bash to interpret that as me running RM with the eye option Okay, additionally, I mean you could do this with any command if you want to be absolutely suicidal This is stupid. Don't do it. It's just a proof of concept Instead of writing this well, actually, I'll just delete this instead of writing this you could do this That is whenever I remove just remove everything recursively Okay, that would be suicidal because if you accidentally run remove on a directory the whole directory is gone Okay, so this this would be a good alias to have and you can actually put other aliases in here I noted that copy by default does not copy recursively that is if you want to copy a directory You have to give it the R option. Let's say you find out redundant. You I mean you're always I mean if I'm copying it something I always want the R option so you can do something like this You can say okay whenever I copy give it the R option. Okay, so that's the kind of stuff that you can do So I'm gonna this is a text editor. I'm in I'm gonna write out the file I'm just looking down here and then yeah save that exit So nano of course if you don't know is a text editor nano is sort of like training wheels for Vim If you don't know what Vim is Vim is the text editor I mean technically it is the standard editor, but Vim or vi is the editor that basically people on the command line use You should learn it. I've done videos on it a lot of other people have done videos on it Vim is very powerful because it can turn you can type keys like a normal text editor But you can turn every single key into also a key binding a shortcut that makes editing text very efficient But nano works if you you don't know what you're doing or you need to all this All right So anyway, so we got a good bit of stuff. Let's do a little review right now So PWD prints where you are by default. You will be in slash home slash your name LS Lists contents. You can of course run man at any time to see all of the information about a particular command that you might need You can run Commands with particular options. We talked about LSA to print all your hidden files or your dot files Hidden files or anything that starts with a dot on, you know, Linux or macOS or anything You can run it with the L option as well. You can make directories You can make directories with MK DIR that already exists another Another new deer. Okay, so you can make directories with MK DIR. There it is you can remove directories with MK DIR you can complete file names with tab stuff that stuff like that if you want to be suicidal Let's be suicidal and delete lots and lots of stuff Actually, look did I already? Delete all the stuff that was in here. I don't know. Maybe I did who cares was I even in work I'm trying to remember where I was when I was making all those directories. Who cares it doesn't matter But if you want to delete something Suicidally, you can run RM with the recursive option other stuff like that. We talked about moving files We talked about copying files. Let's say I want to copy this file stall to my home directory You just run that you can also copy sequences, you know Regular not regular expressions, but glob matches of files notice. I have two PDFs in this directory I could copy both of them to my home directory by doing this copy Star PDF to my home directory and that will copy both of them to my home directory or also I mean you could actually do any kind of sequence. It's not just with Extensions notice both of these start with three so I could actually do this as well. I could say copy three star To let's go to this directory. Okay So that will write them in there So that is so those are sort of command line basics now There are a lot of things I have not touched on but that's just navigating around In another video. I want to talk about piping and because that's really where I mean right now You you're just learning how to sort of walk around and you're right. We're actually moving around very inefficiently We're not doing anything fancy. So in another video coming up soon I want to do stuff on the basics of piping which really shows you the the Great stuff that you can do on the command line. So anyway, wait for that and I'll see you guys next time