Transcript for:
GUI and CLI Basics

hello and welcome to another tutorial um my name is matt cervantes and i am a computer science professor at butte college um and so in this video i'm going to be walking through the basics of using uh the command line interface or a cli is sometimes called for an operating system now the the primary uh audience that i'm intending for this video is the the folks who are going to be taking or are currently taking a programming class with me but this information is certainly useful to anyone who is just interested in becoming more familiar with the command line so i'm going to put it up on youtube and then it'll benefit anyone who would like to to have this information now to kind of get things started with this though i'm actually not going to i'm going to kind of detour from the command line interface and i'm actually going to talk a little bit about something else and hopefully kind of work our way towards towards the command line from some place that i'm hoping everyone is comfortable starting out and that is a thing called a gui all right now the first thing i'm if i say that gui what is a gui well a gui is just a graphical user interface right and uh and the reason i want to start here is because this is what i would assume most people are familiar with when uh when dealing with a computer and really the the thing that sets a gui apart from a cli is that a gui allows a person to interact with the computer with minimal keyboard input now it it's kind of hard to never type anything to a computer that's sort of one of the primary ways but if you have a really good gui you can reduce it down to very very little and that's what most really successful programs nowadays do right and so i've already kind of mentioned this is that guise are really the primary interface that are used by pretty much most people today and there's a few reasons for that um the most the most obvious one is that they're just more intuitive are are far more intuitive than what we're going to talk about with the cli and this is what git has kind of given them the the edge they were certainly not the starting point but they are now clearly the dominant way that people interact and they also provide a common foundation so when when guys kind of came out and they started becoming very prevalent everyone kind of became on the same page it no longer you no longer had to get into the the details of your specific computer system because this graphical user interface kind of provided this nice foundation that could make it easier for you to talk to other people about computers so that's another reason why they're so prevalent today and probably the last and i i don't want to understate this but it is true they're just much prettier to look at and so um that's that's one of the reasons why people use them today so i'm going to go ahead and stop here right and we're going to and i figure we'll just i'm just going to demonstrate using a gui so hopefully everybody here you can see my desktop and this is what you're used to on your computer now obviously i'm doing this on a windows based computer but this is true now on pretty much any major operating system so if you're using a linux distro or you're on mac os x it it doesn't matter they all have some sort of graphical interface and your desktop which is a pretty common word now is a graphical representation of your computer right and so here's what i'm going to do i'm going to do something that's hopefully very familiar to everybody if i want to do something let's say i want to make a folder on this computer well i can just come over here and right click new folder right and then this thing pops up and then i can just type in here folder one of course because that's the name every programmer gives their their folders right so i'm just going to call that and bam so i i used my mouse i right clicked and look what i created a little thing on my desktop now if i want to see the contents of that folder i can right click i can double click on it right and then this pops up like this wonderful little window thing pops up and it's nice and friendly and very easy to understand it's this thing and it's empty right now you can even have a little picture on here that looks just like an actual physical folder so it's much more intuitive right so i get in here and now let's say i want to make a file inside of this folder well i can just right click again new text document let's say and then this thing shows up and now i can write another name for my file so i'm going to call it file1 because that's just how i roll right and there we go so now just with a few mouse clicks and dragging things around and very little typing actually i was able to actually create a folder on my computer and then put a file in it and then if i wanted to i wanted to put some content into this file i can double click on it and then oh look a program opens right notepad opens on on the windows operating system and now i can come in here and now i can actually type some information in here so some information in the file look at that all right and then i'll i'll save it i'll close this right and so this is this is how most people i think are used to navigating and doing things on a computer right and again you can nest the folders i can even come in here and i can create another folder inside of this folder i'm going to make it subfolder one look at that that's great okay and so this is again all this 99 of what i'm doing here mouse right and right clicking and and doing that kind of stuff and so this is what when i say a graphical user interface this is what you're used to okay so now um look we're gonna i'm gonna kind of contrast that a little bit with uh what a command line interface does in a few moments uh but before i venture into that i do want to point this out because i'm trying to make this tutorial as as universal as possible um if you're running on a mac or you're running on like a linux distro the one thing i will point out that's a little different here is that on a windows machine they do have these things this little file extension so let's see how this says file.txt if you did the same operations on mac or linux you may not get this little.txt file and so i did want to point this out because even though it's only kind of tangentially related to this topic it can be confusing to folks so i i i went ahead and i and i made a little slide to talk about this a little bit i did want to mention this so on a windows based computer like i'm on right now that file extension that little dot txt that you saw the actually the operating system itself windows the windows operating system uses that file extension as a way to know what kind of programs are associated with the file itself so so really if i if i broke out of this again you can see that when i double click on this file with my mouse all right how does it know to open up notepad well that's because if you right click on it again if you go over here to properties it actually you can see right here and i'll zoom in a little that the type of file it says it knows that it's a dot txt it actually uses that extension as a way of knowing it and then it knows whenever i see a dot txt i open it with this thing called notepad and you can actually change that if you want you can change this and you can have it from here on out i can use visual studio code if i want to open up.txt files right and if i clicked on this and then clicked ok that's exactly what would happen now i'm not going to do that because i actually like mine open up with notepad right but that's that's the idea behind it so with that in mind that's not necessarily how it works on other operating systems so i just want to point this out so if you are following along and you're on a windows machine i'm sure that made perfect sense if you're on a mac or linux right mac and linux don't actually use file extensions well they do but but the primary way that they associate files with a particular program is through a thing called a mind type now i'm not going to get into it the details of it so mime stands for multi-purpose internet mail extensions okay so it's actually a really old idea it's from like email time all right but it's been widely adopted now so basically what it boils down to is the the information about what program should open up that file is actually baked into the file itself rather than it just being the the name of the file they actually put the information into the file now you can also and i put this as a little bonus thing here those operating systems mac and linux they both can use extensions and some of them do but it's not required so i just don't want that to throw anybody off if i i'm doing something in windows world here um that that that you know isn't equivalent in mac or linux universe then i i i'm just trying to draw that attention here so but it's okay right it's the same ideas are there you can create files you can i'm sure it's right click or do some sort of clicking thing on your mouse and you can create files and folders okay so now that i've done all of that now i'm going to do basically the exact same stuff i just did except i'm going to do it now with a different interface instead of using a graphical user interface i'm going to use a command line interface so in the windows operating system there's really there's two of these but i'm going to use my the one that i like most so here i'm going to do this i'm hitting the command key i guess you guys can't see this and just do powershell okay i'll drag it over here so you folks can see it so this is what i'm talking about when i say cli so in the windows world windows powershell is a kind of cli that you can use to navigate and interact with your computer so the first thing i want to draw attention to here is is this little bit right here that says c colon backslash users matte okay this is actually telling me where i am right now on the computer in this in this command prompt okay and that's very different than how you're used to seeing it if you're used to using a graphical user interface because in a graphical user interface you don't really this is sort of just intuitively understood where i am it's just by proxy of me like i'm just i'm here my mouse is here when i click on things i go into these folders and i can go further down into folders like this right it's more intuitive right but in the end this is actually the same thing as here and you can always tell that at least in windows i'm not sure if this is true in mac and linux but i assume it is you just come up here to this little address bar at the top here and here i'll zoom in again oop oh boy i didn't mean to do that uh okay well we'll just leave it that way i guess if you click here look what you can see it'll actually show you exactly where you are right now so i'm on the c drive in a folder called users in a subfolder mat subfolder desktop subfolder folder one right and that's just where i happen to be right now okay and so when i do this on a command prompt command line right it's it's just more explicit it just tells me that's where i am right now so based on what i just showed you you can tell that i'm actually in a different place this is in a different place right now than this is so if i wanted to get from where i am in the command prompt to where this is this folder is i'm going to need to be able to move around so on the com on the gui right now i'm in c users matt and then i'm in another subfolder called desktop so the easiest way to do this and this is when the first command you're going to need to know how to do in a command prompt is to do cd so cd oh boy that was weird all right you type cd space and here i'm going to get out of that because it's doing weird stuff right cd space and then you just type the name of the folder you want to go into so i happen to know that there's something called desktop right and boom there i am i can see now that i am i'm gonna be doing a lot of zooming in and out i guess um to to do that so now now i'm in the desktop right isn't that great no now let's say i want to go even further down so i know now that this is in uh users matt desktop and another folder called folder1 right so let's go ahead and do that cd folder one all right and i hit enter and look where i am now i'm in a little further and so at any point in time you can always just see where you are now on a linux or a mac machine this might not be here depending on what shell you're running and so you can there's a command that can also just tell you where you are at any point and that's pwd right and it'll work in powershell as well it's basically just a path right and so right now when i type pw it literally told me exactly where i was although i already knew it because of the the way this shell is set up so you could also do this command in um in a mac or linux and that and then you would know exactly where you are okay so now that we know where we are that's good but let's say but that was me cheating a little right like i knew where i was because i was using this uh gui over here to kind of help navigate what if i didn't know what if i didn't know what was in folder one well lucky for us there is another command that is good to use when that is the list command or ls so if you just type ls in a folder that you happen to be in and hit enter it will show you every single um thing inside of that folder so look where i am now this is telling me in this this mode thing there's a whole kind of coding that you need to know if you want to understand this better but in the end the d stands for a directory so it's telling me this thing called subfolder1 is a is a directory or a folder right and then this other thing a is actually telling me this is a file right and i named it file so there they are so there's my subfolder one and there's file one just like i had in my in my gui over here they're the same things right so there's a way to navigate around so you can use cd to just navigate your way down down down into whatever folder you want to get into right and then you can use ls to see what's inside of every folder as you go right and so i can take this another step folder i can do cd folder folder or subfolder one right so i need to go sub folder one right and now i'll do ls again and there's nothing in it right so that's nothing shows up when i do ls as you would expect i can also type clear here in powershell and it'll just wipe out everything that was there that's nice okay so now i'm in subfolders so now let's say okay i i don't want to be in subfolder i want to get back up here to where file 1 was so that's the other thing you can do you can do cd space dot dot and that'll take you up a directory so i'll just zoom in here so you can see that a little so i was in subfolder one i did cd space dot dot and that took me up back up to folder one so you can always use the dot dot to represent one folder like above where you are so let's say i went here subfolder one goodness this is going to be the the fun part that i do all day here let's do this whoops okay there we go uh subfolder one right i'm back in subfolder one now let's say i wanted to go up two directories i could do cd dot dot slash dot dot and now look where i am there do this again see now it took me up from subfolder one up to subfol to folder one right and then it went up one more to desktop so now i'm here so this this cd command is is kind of your your ticket to navigating around in your computer so here i'm going to go back down into folder one i'll do ls and look there's all the stuff that's in there as we saw before okay so that's cd and ls those are probably your biggest useful commands on the command line now let's say i want to be able to look at that file well there's a couple commands you can do i'm going to show you cat if you do cat file 1 that will actually just show you and just spit out to the terminal what what is in that file so here it is some information in the file it's just telling me exactly what's in it so it's the same as if i had double clicked on this and just looked at it here it's the same thing isn't that neat all right but let's say i wanted to edit this file well if i wanted to edit it this is actually where windows is a little different than the other operating systems and in windows there's no way to do that in the command line right so you actually it's the expectation is that i'm going to open up some sort of a program to do the editing and in this case that program the computer knows well if it has a dot txt file on it that means i'm going to open it with notepad so if i just type in the name of the file file1.txt and hit enter look what opens it just automatically opens up the the program that i can use to edit it and then i can edit it all i like some information here's more info right i'll hit save i'll close it right and now here what i'll do i'll cat that information out and it'll actually have the new information right there isn't that great okay so you can you can navigate around you can look in the files you can run the files let's say i want to make another folder you can do mkdir and i'm going to make another folder in here subfolder 2 let's say and look what i just did i just made a folder and then look what happened if you look up here in the back in the graphical user interface look what it made it made subfolder 2. it just sort of showed up as soon as i did that so the point i'm trying to make here is that this this interface right here is doing the exact same thing that that you're doing when you click on things in the windows gui right or any kind of gui this there's no difference between what they can accomplish just the way in which they go about it so in this interface in the command line interface you kind of need to know these commands you need to know things like cd or ls or mkdir right there's a few other ones and i'm going to show you those in a second but i wanted you to be aware that those that that's really what we're talking about that there's there's really nothing you can't do in the command line that you could do in the in the gui they're they're the exactly the same thing okay so i've already showed you sort of the basic uh commands that you can use on the command line interface to navigate around and make directories and stuff but there's there's really no end to the number of resources available to you to be able to figure out all of the commands available and that's and that's really what the internet is for and so i actually went ahead and went and found these i'll put these in the description of this video and i like this one in particular because this one actually is showing you that the equivalent so this is why one of the reasons why i use powershell so much is that it mimics and uh the same commands that linux uses and linux and mac kind of use the same ones and so in this particular one that you can see well here's here's pwd like we just talked about there's cd there's ls find we didn't even talk about that you can copy you can remove make a directory you can touch you know all sorts of great stuff and so um in this in the i would highly encourage you to to do your own google search but i i will share this one and then this will also just act as a list of things that you can go find i found another one here this one's actually more unique to linux but hopefully you can see the similarities here this is just the linux basic commands and like what do you see the same stuff pwd cd ls cat right they're all very similar um in fact for being really honest about it uh microsoft when they made powershell they kind of blatantly ripped off uh the same commands that that uh linux had already so so you if you learn powershell sort of setup and you're kind of already set up pretty well for ever transitioning over to one of those other operating systems as far as the cli is concerned now i am going to pause here for a second i'm going to kind of go back to what we were doing previously let me go back to my slide here all right but i do want to talk about the different types of command line interfaces that exist so as you just saw i'm using powershell inside of windows right but obviously different operating systems have different um different you know tools available to them so i wanted i just kind of made this list to help you out so on a windows computer there are really two different command line interfaces there's uh the most the older one i suppose is what's called the command prompt sometimes people will just call it cmd right and this is actually in modern windows operating systems this is really just a kind of a throwback to the old dos operating system and so i will demonstrate that really quickly just because i happen to be on a computer so i can open up the i can hit the window key on my computer type cmd right and then this thing will show up and it's black instead of blue i guess right and it's it's actually a different program than powershell powershell is a different command line interface and they have little tiny differences between the two as far as uh most of the commands although the reason why i'm using powershell is because it's much newer and far more robust this is actually a very old it's emulating dos really um and it and there are some little differences in just the syntax but mostly there's just a lot of this uh tooling that i would like that most people would like to be able to use nowadays just doesn't exist here but you can do simple things like you can uh cd and i can go into desktop again right and here i am i can cd into folder one i think that's what it calls yeah and then now here's the thing a funny difference there's no such thing as ls here it doesn't know what that is because back in the old dos days they used the word dir and now that's how you can see what's inside of it right so there's other little little nuancy differences but in the end it does effectively the same thing i can make directories i can copy files i can launch programs i can do all that same stuff from here right but i'm going to encourage anybody who's in my class and frankly anyone i talk to to just use powershell if you're on a windows computer okay so that's kind of the windows world all right so there's there's the command prompt and there's powershell now um if you're on mac or linux there's actually a bunch of different shells that are pretty common among among those two operating systems in particular so the most common one by far is bash right and so you if you open up like on a mac you can open up the terminal i think is what they call it um you're running bash i think by default um and linux i think bash is the is the top but they have other ones they have uh t tc shell uh z shell um sometimes and then they have like the corn shell right so i think these are the four that are just kind of there by default on linux and mac you don't really even have to do much i think you just there's some commands you can run to switch if you want so these are the different things and much like how uh the command prompt and powershell have small differences between what they can do and what they can't do that's sort of the same thing happening on these operating systems okay and the other thing that linux has is linux actually has many many more uh command shells that it has available to it i certainly couldn't enumerate them all here but i wanted you to be aware of the that those differences exist okay so um so now let's talk about now that i've kind of demonstrated like so what is cli is a command line interface and it allows the user to interact with the computer primarily using a keyboard as you as you saw me so everything that i was doing i was just typing it i wasn't using the mouse i wasn't having to do much uh you know mousing around or using the graphics of the computer i was just typing where i wanted to go and it was taking me there and the thing about the cli is that it it pretty much for every every operating system it does require a slightly deeper understanding of that computer system to be able to kind of accomplish your goals and this is what is sort of off-putting i think to most people but if you're interested in getting into uh computer programming and wanting to explore that as a as a you know as a career path or even just an interest you're going to want to get comfortable with the command line interface because the i've never seen a program an education program that didn't initially teach computer programming on the command command prompt on a terminal like this um so this is where where you're going to spend a lot of your time and the kind of programs that you'll run just like how i was in here and i could just run run a program like notepad you could just type notepad and it'll just open it up right just like that you can run command line programs programs that when you run them the output is not like a graphical thing that pops up but actually information that shows up here in the terminal and that's and that's why you start there because that's kind of where it all begins all right well that pretty much wraps up this video i'm hopefully i demystified a little bit of what the command line interface is and uh folks can get going and start digging down deeper and into computer science all right thank you have a good one