Join Mike Meyers for an in-depth discussion in this video Windows command-line basics, part of CompTIA A+ (220-902) Cert Prep: 4 Virtualization Printers and Troubleshooting.
- The beautiful thing about computers is that there's so many ways to give it input. For example, with my Windows 10 system, "Hey, Cortana, what's the weather going to be today?" Taa-daa, and I instantly know the weather. Now, I could also, for example use a mouse. Hello, computer, oh, sorry, that's, old reference. Don't worry about it. So, I can use my mouse to click around on my system and open stuff up. I can start Word, whatever I'd like to do, using the mouse.
I could also use a keyboard, but usually we don't use the keyboard so much for commands. We use voice or we'll us a mouse to actually execute programs, get things going, close programs and keyboards are traditionally, and there's plenty of exceptions to this, where we just enter the data for whatever we happen to be doing. Now, voice and mice are great, but sometimes, they fall a little short. "Hey, Cortana, I need you to go into my Documents folder. "I need you to find all of the documents, "and not only check that folder, but any subfolders, "find every Word document that starts with the letter J.
"I need you to move all of those, in one command, "over into my Backups folder." Yeah, Cortana's going to have a little bit of a problem with that particular one. Oh, thanks for the Web search. Anyway, when it really boils down to having to do heavy lifting, one of the tools that we go back to is one of the oldest interfaces that have ever been in the world of computers: the Command Prompt. The Command Prompt pre-dates anything with mice or graphics or anything like that.
And, in the first generations of computers, it was the way we did things. In fact, the Command Prompt pre-dates even monitors. It goes all the way back to when you typed into a keyboard and things came out on paper. So, what we're going to be doing is, we're going to be looking at the Command Prompt, in this episode, for Windows. However, every modern operating system, no exception, also uses Command Prompts, but we'll be looking at those in other episodes. So, what I'd like to do is get started with Windows command line basics.
And, the best place to start is, "How do you get to the command line?" So, here in Windows, what I'm going to do is, I'm going to just go down into my Search Bar and I just type in CMD. And, you can see, this is Windows 10, in this particular example, and he sees that I want to start the Command Prompt. So, CMD, I'll hit Enter. Taa-daa, welcome to the Command Prompt. Now, I want you to take a good, hard look at this guy. The Command Prompt, first of all, consists of a prompt. This prompt is pointing to where your computer is looking at, in terms of your folder structure.
So, right now, I'm on my C Drive in a folder called Users and in a subfolder called Studio. Now, I need to warn you, in the Command Prompt world, we tend to use the word directory. Directory, folders, folders, directory, it's the exact same thing. So, don't let that confuse you. Now, taking a look at this prompt, you can see that it's got a little flashing cursor there. It's waiting for me to do something. So, what we do, is we enter commands. So, I'm going to teach you your first Windows Command Prompt command, right now: help.
No, that's the command. So we type in help and what you'll see is a whole bunch of stuff that has scrolled past. You've got to remember, the Command Prompt was really designed originally for paper terminals, so one of the problems that a lot of people do when they first see a Command Prompt is they want to, like, click up and stuff like that. In the world of Command Prompt, when you're messing with a Command Prompt, you just type the command again. So, watch what I'm going to do right here. So, here's your second command that I'm going to teach you: clear screen.
So, CLS, so I hit that and it clears the screen. Now, you'll notice, as I'm typing this, it's in all caps. So, what I'm going to do is I'm going to turn off my Caps Lock and I'm going to type the commands again. So, here I'm going to type help. In the Windows environment, typing in upper or lower case makes absolutely no difference, at all. So, remember that when you're dealing with the Windows Command Prompt. So, what I'd like to do now, is we're going to type help, one more time and it scrolls past.
Now, one of the things you have in a Command Prompt is something called a switch. So, what I'm going to do is I'm going to type, help, a little bit differently this time. So, let's say I want to use the CLS Command, the Clear Screen, but I'd like to have some help about it. So, what I'm going to do is I'm going to type in a slash question mark, jut like that. That is a switch. A switch is a little bit of text that you add to the end of a command to be able to get it to do something special. And, what I'm doing here, is I'm saying, "Command Prompt, I don't want you to run "the Clear Screen Command, "I want help for the Clear Screen Command." So, I hit Enter, and as you can imagine, the Help says, "It clears the screen." Thanks, Windows! Now, that's the basics on this, so we're, go ahead and get this running.
Now, what I want to do is, let's say I'm done doing whatever I'm doing in the Command Prompt. So, to close a Command Prompt, well, the easiest way, the best way to it is to just type, exit. So, I type exit and the Command Prompt's gone. Now, the Command Prompt, as you might imagine, is an incredibly powerful slash dangerous tool. And, there are commands you can run in there that will basically wipe your hard drive do all kinds of horrible, horrible things. So, in the Windows environment, we often have you run the Command Prompt with Administrator privileges just to protect you from doing awful things.
For example, you can re-partition your hard drive from a Command Prompt, but you can only do that with Administrator privileges. So, let's run the Command Prompt again, but this time, let's run it as an Administrator. So, here in Windows 10, all I need to do is right-click on my Quicklinks, and you'll see I've got two choices here: Command Prompt and Command Prompt (Admin). So, if I click on this, and once again, I'm right back into my Command Prompt. But, this time, if I, well, you'd have to know the right commands, but if I typed them in, guess what? You are, have total ability to repetition your hard drive or reformat it or do all kinds, delete users, bad, bad things.
So, on a lot of the commands that we're going to be seeing, not only in this episode, but in other episodes, you'll normally want to run with Administrator privileges. So, in general, I'm always going to start in Administrator Privileges. Okay, well, that at least gets you started in terms of understanding the Command Prompt. But, what I'd like to do now, is start to go through some of the more important basic commands and probably the most important one of all is dir.
In a regular Windows graphical environment, I can just double-click on a folder someplace and see what's in that folder. Just double-click, open it up and then I can see all my files and folders. Now, at the command line, though, you don't have that option. In the command lime, you actually have to say, "Show me what's in the folder I'm currently at." So, what were going to do here is learn about the dir, I mean, d-i-r command. Now remember, directories and folders are the exact same thing, there's no difference.
So, dir stands for directory but in my mind, dir means, "Show me what's in here." So, let's go ahead and run the dir command. So, in this particular case, I'm in the Windows folder. Now, when I say, "I'm in there," what I'm saying is, "the command line is pointing "at c colon backslash Windows." So, right now, I'm, in essence, in the Windows folder. So, I'm going to type, dir and I can see everything that is in that particular folder.
Now, let's take a look at what we're looking at, here. Now, there's going to be files and folders, so we see a little bit of both. First of all, all of these, where it says, DIR like that, that's a folder. And, if you're familiar with the Windows folder structure, some of these should look familiar to you. All of these other ones are actually files and what we have here is the date and time created, and the, this is the size in bytes and these are actually the names of the different folders and files.
Now, if you were paying attention, when I typed dir, there was stuff that kind of scrolled up past the top. Now, we'd be tempted to want to scroll back down, but when we're working in a command line, traditionally what we do is simply type it again. So, what I'm going to do now, I'm going to show you a couple if ways to type the dir command, using switches, to help us see what's on the screen. So, the first thing I want to use is wide. So, I'm going to type, dir/w and I hit Enter, and now you can see everything's wide.
Now, it's going to sacrifice some of the information. I can't see byte size and I can't see the creation date and time. But, I can tell, for example, files which have their file name and all these fellas in brackets, those are going to be individual folders. Now, you'd say, "Well, Mike, I want to see "all this information." So, yep, there's another way to type the dir command, sing a different switch and this one's the p switch. I'm going to type, dir/p and, now, it gives me, p stands for page, one page at a time.
So, it gives me the first page. And then, press any key to continue. And then, press any key to continue. And then, press any key to continue, and I just keep pressing the key until I've seen everything that is within the contents of that. Now, one of the things I want you to take a look at, is how I type those commands. So, what I'm going to do is I'm going to type, dir/w. Now, you'll notice there's no spaces. It's just dir/w, if I hit Enter, it works. I'm going to type dir space slash w and that works too.
Now, one other little trick, when you're working in a command line, if it gets you in the middle of something like this, where it says, "Press any key to continue," you can just keep hitting, hitting, hitting. But, sometimes, this could take forever. So, a nice little trick is just to hit Control + c and you'll see that puts me right back to the command line. So, that's the basics of the dir commmand. What I want to do now, though, is I want to move around within the directory structure of my drives. So, to do that, we need to have each new command called, "cd".
In regular Windows, if you want to open up different folders, you just fire up File Explorer and then you click on whatever folder you want to look at and if there's a subfolder in there, you click on there. You click and click and click! At the command line, in order to move around your directory structure, we have to use a command cd, cd stands for change directory but we just cd it. So, to me cd means, "Point to a different folder." So, let's march around with the cd command and have a little bit of fun. Now, you can see when I first open up the Command Line Interface on this particular system, it goes to C:\Users\Studio and that makes sense.
I logged in as Studio, so it's going to point me towards my stuff first. But, if I want to move around, I'm going to use the cd command. So, the first and the most important cd command there is, is cd backslash. So, watch this. So, I'm going to type cd\, hit Enter and this puts me at the very root of my C drive, the folder that is no folder. If I was going into my File Explorer, where I would just click on My Computer or This Computer or Computer or whatever version of Windows you have, when I just click right on the C drive, that's where it's going to put me.
Now, the dir command works just fine here. So, we type dir and we can see the most core base folders. So, there's Users, for example. Here's my Windows executable stuff. Here's my installed programs, all kinds, and a few other things that other people put in a long time ago. Now, what I'm going to do, here, is I'm going to use the cd command to get back to my Users slash Studio folder. So, let's go ahead and do that. So, what you would do, is you'd type what that prompt would look like if you were there.
So, let's think about this for a minute. When we were in the Users Studio folder, it said C colon backslash users backslash studio cursor, waiting for us to do something. We call that the path. So, I'm going to type in the path. So, I'm going to type, cd space c:\users\studio and I hit enter and here I am. So, if I type dir, I better be seeing something different than that dir I just typed and I most certainly do. Now, the one thing about the Windows command line is that you can use all kinds of shortcuts.
So, I'm going to go back to that root directory by typing cd backslash and I'm going to show you easier ways to type the cd command. For example, one of the things is that everything I'm doing is within my C drive, so I don't have to type C colon every time. So, watch this. So, I'm going to type cd\users\studio and you can see didn't type C colon and it still works just fine. So, that's one little shortcut we can do. Now, that's great because in this particular case, I knew exactly where I wanted to go.
A lot of times, you're using the cd command and you want to just kind of explore around a little bit. So, let me show you a couple more tricks. The first one I want to show you is, well, let me type dir one more time. If you look up at the top, do you see dot and double dot, right up here? These are kind of like the trail of breadcrumbs that your file system uses to keep track of which folders are connected to what. So, you know we're in the C colon backslash users backslash studio. What if I just want to go to the users folder? I want to go up one folder.
Now, I could type cd backslash users and hit Enter and that would work, but watch what happens here. I'm going to type cd space dot dot and it brings me up one click within the folder structure itself. So, we use little tricks like that. So, I'm going to type cd dot dot again and if I do it right, it puts us right back to the root directory. Okay, so those are some of the basics on it. Let's try a few more. So, what I'd like to do, first of all, oh, by the way, let me show you a neat little trick. What we can do is you could hit your Up Arrow key.
I'm just pressing my Up Arrow key, one at a time here, and you can see command that I've typed in my history are stored there. So, it's a very convenient way, if you're typing a command and you need to type it again, well, just hit at the Up Arrow key. So, I want to go back in to my Users Studio. So, here we are in Users Studio, again, and, this time, what I want to do is, I'm going to go back to my root directory. Now, what I want to do is go back to Users Studio, but first I want to go to Users, then I want to go to Studio.
So, watch this. So, I'm going to type cd and now no slashes, no nothing, and I'm just going to type users and it brings us down one, into the Users. This only works if you're going to a folder that is one down from where you are right now. So, let's type cd space studio and hit Enter and now you'll see that we've got all the way back down to Users slash Studio. I would say 85% of the work that I do in a Windows environment at the command line is using the cd command and the dir command.
Most of the stuff we're doing at a command line is getting navigated to a particular place in the directory structure, typing dir to make sure that you're there and then, using other commands to do stuff. Make sure for the A+ and the real world you are very comfortable with these Windows command line basics. (cheery jazz music)
Here CompTIA expert Mike Meyers prepares you to answer questions about slightly more advanced topics: "super tech" skills like managing files via the command-line interface, creating virtual machines, connecting to the Internet, installing printers, and troubleshooting startup and application issues. Each lesson prepares you for a related topic on the 90-question A+ exam.
Details about the certification and the exam blueprints can be found at https://certification.comptia.org/certifications/a.
- Working with the Windows and Linux command lines
- Manipulating files, folders, and permissions via the command line
- Using the Recovery Console and Windows Recovery Environment
- Troubleshooting software
- Examining virtual services: IaaS, PaaS, and SaaS
- Troubleshooting Internet connections
- Installing local and network printers