Windows Command Line Tools – CompTIA A+ 220-1102 – 1.2

The Windows command line is a powerful tool for file management, information gathering and troubleshooting. In this video,  you’ll learn about file system commands, format, copy options, Group Policy commands, and much more.


The Windows command prompt allows you access to the operating system through what we call a CLI– a Command Line Interface. This brings up a window. And you can type commands in in that window to interact with the operating system.

Most of the commands that you’ll learn in this video can be run by anybody with standard privileges. These are the privileges associated with any user who might be logged into your network. This works for almost all commands that the users might use, but if you need additional rights and permissions, you can use an elevated prompt, or an administrative prompt.

This means that you’ll need to be part of the administrators group. And when you start the command prompt, you’ll need to choose the option to run as administrator. You can also type the command cmd, which stands for the command prompt, and type in Control+Shift+Enter to automatically launch the command prompt in administrative mode.

This is the same process whether you’re in Windows 10 or Windows 11. In this case, we’ll use Windows 11. We’ll click the magnifying glass to search.

In my case, I’ve already run the command prompt in the past. And you can see it listed on that screen. Or I can simply type in cmd, or command prompt. And it will search through and find me matches for what I’m searching for– in this case, the command prompt, which shows me the options to open, run as administrator, open a file location, pin to the start, and pin to the taskbar.

In this case, let’s click the Open option. And it will open the command prompt, giving us access to the operating system. As you can see, the command prompt doesn’t provide you with any information once you start up that window. You’re put at a prompt, and it’s up to you to know what to type next.

There are ways to get some additional assistance through the help command. The help command can be used to give you more details about any of the other commands you might use at the command prompt, like dir, chkdsk, copy, and anything else that you might need to use when you’re working at the command prompt. You can also use the command with a /? at the end, which provides you with the same help text that you see when you use the help command.

And if you need to close this window, once you’re done using the command prompt, you can simply type exit, and the entire window will be closed. We’re back at our command prompt. So we’ll use the help command and copy to give us information on how the copy command can better be used. And you can see, there are many options available to copy files and other directories within Windows.

And we can see all of the different options by using that help option. If we were to clear this screen– I’m going to type cls to clear the screen– and use the copy command /?, you can see we get exactly the same information. So if we’re using the help command or using the /?, either one will provide you with more information about how that command should be used.

You may be familiar with using Windows Explorer to be able to graphically view all of the files and directories on your system and be able to rename or move any of those files around. But you can also do this from the command line itself. If you’d like to see all of the files available in a particular folder, you can use dir, which stands for directory list, to be able to list all of the files and directories in the current folder.

You can also use the cd command, or chdir, to be able to change or move to a different directory on that system. You would use the backslash to be able to delineate between different folders in that hierarchy on your drive. Another useful option at the command line is to use two dots, or two periods to specify the folder that’s just above the folder where you happen to be working. This is especially useful if you need to move backwards through the file system, and those two dots can help you do that very quickly.

You can also create or remove folders from the command line using the mkdir, or rmdir commands. We very often abbreviate these when we’re typing to md for the mkdir, and the rd command for the rmdir. This makes it very easy to manage the file system at the command line, which can be very useful if you don’t have a graphical interface available when you’re troubleshooting.

Let’s use that dir, or directory command. You can see that we’re currently in the C colon backslash users backslash professor subdirectory. That’s my user subdirectory. And if we type dir at the command prompt, we can then get a list of all of the files and folders that are in the working directory, users Professor Messer.

And you can see, most of these are directories. So I have additional folders within this current folder that I can then store other files in. If we were to look at this in File Explorer– I’ll click that folder at the bottom of the screen that brings up File Explorer– you can see, there is a local disk listed. I do have a Users folder within that.

And within the Users folder is the professor’s folder. And you can see that the list of all of those folders that we saw at the command line are also shown within File Manager. And you can see that all of the folders that we saw at the command line are also listed in the File Explorer.

Let’s now create some folders and remove some folders, and see how that changes things in File Explorer. I’m going to move the File Explorer to the right side of the screen. And we’ll move command prompt to the left side of the screen so we can really watch what’s going on.

Let’s create a directory. We are in our Users Professor Messer folder. So I’m going to use the m d command with a space, because I want to put this folder in my current directory. And let’s call this folder reports. And if I hit Enter, you can see in File Explorer that I have a new folder that was created, called reports.

I may have just realized that I didn’t want a folder named reports. So I can use the rd command to remove the reports folder. And when I press Enter, you can watch in File Explorer that the reports folder will disappear, because we have just removed it from the file system.

We can also use the change directory command to move through this different file structure. For example, if I use the cd command at the command prompt and specify the Documents folder, I’m going to start typing doc. And then, I’m going to hit the Tab option to autocomplete everything that I was typing in.

It automatically fills in the rest of the document’s name. And if I hit Enter, you can see that our working directory is now changed to users, professor, and documents. I can then use the dir command to see if there’s any files within that folder.

And there is another directory within that folder already named reports. If we would then like to move back to the previous directory that we were in, which would be users professor, I can use the cd command again. And I could type in manually users backslash professor to move back to that directory.

Or you can simply use the shortcut, dot dot, which will move back one directory. And that leaves us at C colon backslash users backslash professor. When working inside of Windows, we need some way to designate where certain files may be located. And different drives have different letters that we associate with them, called drive letters.

These drive letters are usually associated with a partition or a remote share that’s located on another machine. And we usually associate that particular drive letter with that particular location. For example, it’s very common for our local storage drive to be associated with the letter C.

So we put a colon right after the C to designate that that is the storage drive that we’re referencing. We’ve already seen this drive being used at the command line when we had the C colon backslash users backslash professor. The C colon designated that we were accessing our local storage drive.

And from that local storage drive, we were accessing the subdirectory users, which has within that folder the subdirectory professor. And you can see, if you have multiple locations or multiple drives in your system, each one of those drives will be given a different drive letter. You can see on this system, I have drives for C colon, S colon, T, U, V, W, X, Y, and z.

And of course, we have other letters that we could associate with other folders. So if we connected to a remote share, we might want to call that drive drive G, or drive H. You have many options when assigning these drive letters. And usually, you’ll pick something that people can remember so that you can tell them to store their user files in drive H or store public files in drive G.

One of the challenges you’ll find very quickly in a support role is, you may have many different command line windows up on the screen at once. And these may be all connected or associated with different devices. The real challenge is when you’re typing at a command prompt, which computer are you typing these commands into? Fortunately, Windows has a command called hostname that will put the name of the computer at the command prompt.

This means you can type in hostname and confirm that the next command you type in is really going to be applied to the correct system. The hostname is one of those straightforward commands that also provides a lot of utility. So if we type in hostname right at the command prompt, the only thing the computer provides back is the name of the host.

In this case, the name of this computer is Daedalus. So anything I type at the command prompt will make changes on the system that is named Daedalus. If these changes are required to be on a different system, typing hostname can give us an early warning that we may be in the wrong window. And we’ll need to go find the correct window to be able to make those changes.

When you create a partition in a file system, it’s an open area that you could then add other information to. But you need some type of file system to be able to store information into that partition. The process of installing that file system or configuring a file system in that partition can be done in Windows using the format command.

The format command will write a new file system to this partition, effectively erasing anything that may have been there previously. So if you’re using this format command, make sure you specify the correct drive, or you could accidentally remove data from your system. In this example, I previously created a partition.

And I’ve assigned a Windows drive letter to that partition called K. That means all I have to do is use the format command with K colon. And this tells Windows to create a new file system on that drive K.

The default for this drive is to write a FAT32 file system, or File Allocation Table 32-bit. And then, it verifies the size, and then initializes the partition. You can also provide a volume label so that you can recognize what this partition happens to be.

In this case, I used info as my volume label. And when it’s done, it shows you a summary of the available disk space and how the file system was created. As I mentioned earlier, the format command can permanently delete data. So make sure that you’re specifying the correct drive, and that you have backups of anything that may have been previously saved on that drive.

Just as you can copy and paste files in File Explorer, you can copy files at the command prompt using the copy command. The syntax of the copy command uses copy, the name of the source file, and then the destination where you would like to copy that file. You can also add different flags or options to the command– for example, /v. It will verify that the file that you’ve copied is identical to the original source. And if you use /y, you can tell Windows to skip over any prompts where it might be asking you whether you would really like to copy this file or not.

I’ve changed directories into a folder that’s on my C colon drive. It’s under users, professor, documents, and reports. And if we perform a dir command at that prompt, we can see there is a single file in this folder called P3K-447-report.txt. Let’s say that we’d like to create a copy of this file.

And we’ll make a copy in our existing directory. So I’ll use the copy command. I’ll specify P3K. And I’ll hit the Tab key to autocomplete.

And let’s say that we would like to call this duplicate.txt. That is the syntax for the copy command, which specifies the source and specifies the destination. And if we hit Enter, it will tell us that one file has been copied.

If we perform another dir command, if we hit Enter, we can see that we have two files now in this folder. One is our original P3K-447-report. And the other one is the new file we created called duplicate.txt.

If we were to perform that command again– and I’m going to do that by hitting the up arrow to show that copy command– we’re going to copy that same file to that same destination. But of course, there’s already a duplicate.txt file, because we just created it with the previous copy command. Windows tells us that there is a file there already.

And it says, would you like to overwrite duplicate.txt? And you can either type Y for yes, or write the entire word Y-E-S and hit Enter. And it will continue to copy that file. Of course, you could always choose the option of no.

And Windows would not overwrite that file. If we already know that we would like to overwrite this file, and we would not want to be prompted for this yes or no option, we can use the copy command again with the /y option. And we’ll specify again– P3K-447-report.txt as our source and duplicate.txt as the destination.

If we use this command with the /y and press Enter, we don’t get the previous prompt to overwrite the duplicate.txt, because we’ve already told Windows, yes we do want to overwrite that file. And it simply performs the file copy.

The copy command is great for copying files that may be in a particular folder or copying a large group of data from one location to another. But what if you have multiple files that are located in multiple folders, and you would like to copy all of those at one time? You can use the xcopy command with the /s.

This specifies subdirectories so that everything we’re copying will not only be in our current folder, but every other folder that happens to be underneath our current working directory. We can also have a source, such as the Documents folder. And in this case, we’re specifying that we would like to copy these files and all directories to the M colon drive under backslash backups.

And if we use this command, it will go through all of the files that are underneath our current working directory, which in this case is users administrator. So under users administrator is a Documents folder. Underneath the Documents folder is a mission reports folder.

Underneath the mission reports folder are individual mission reports folders, and then separate reports underneath those. There’s also ship diagnostics folders. And underneath that folder are also multiple folders.

If we were to specify these as individual files, we would need to type in separate copy commands with each one of these. But by using the /yes to copy everything in a subdirectory, Windows goes through the entire group all at once, copies all seven files. And we didn’t have to type anything else at the command line.

Of course, there’s always more than one way in Windows to complete a function. And there is another copy command you might want to be familiar with called robocopy. This stands for robust copy. And it’s designed to be a better version of xcopy.

This is a functionality included with Windows 10 and Windows 11. And you may find yourself using robocopy in many cases instead of xcopy or the copy command. The robocopy command provides extensive features for copying files from one location to another.

Let’s look through just a few of what these options might be. I’m going to type in the robocopy command. But I’m also going to use the /? to get the help screen for robocopy. And you’ll see that a lot of information goes by on the screen.

Let’s scroll all the way back up to the top. And you can see a summary of what robocopy does, and then a list of all of the different options you can use when copying files. This provides you with options that may be obvious, such as copying subdirectories, but not empty subdirectories.

But if I scroll down a bit, you’ll start to see more of the detail you can get from robocopy. For example, you can create files on the destination device using the 8.3 file allocation table file names only for compatibility with older operating systems. Or one that I like– you can change the inter packet gap in milliseconds to specify how much bandwidth might be used when you’re copying this file.

This can be very useful if you’re copying files to a remote site, especially a site that may have limited bandwidth. And you don’t want the copy command to overwhelm all of the bandwidth that you have available on that link. You can also give robocopy very granular commands.

For example, you can tell robocopy to only copy files during a certain time of the day. Or you may be copying files to a remote site, and the connectivity to that site tends to go up and down throughout the day. But you need to transfer a very large file.

So you can have robocopy begin the copy process. If it does lose connectivity to that site, it will simply wait until that connectivity is restored. And it will then resume the copy process. If you were using copy or xcopy, those commands would see that the connection was no longer available. And it would show you an error message instead of resuming that copy.

It’s not unusual in Windows that we may need to restart the system, especially if we’re installing a new driver or new application. At the command prompt, you can perform a restart by using the shutdown command. The shutdown command, as the name implies, will shut down the system.

You can specify the /s to perform a shutdown. And if you’d like, you could even use the /t to specify an amount of time in seconds to wait before the system is shut down. If you wanted the system to then restart after shutting down, you can use the shutdown command with the /r option.

And then optionally, you could use the /t to specify how many seconds it should wait before shutting down and then restarting the system. If anywhere in here, you feel that you don’t want the system to shut down, you can abort this process by using shutdown /a. Let’s perform a shutdown on my Windows 11 system.

We’ll use the shutdown command with a /s to shut things down. And I’ll specify a time frame of 60 seconds. And Windows tells us that you’re about to be signed out.

And Windows will shut down in one minute. We may decide here that there’s another step we need to take before we begin the shutdown process. So we need to stop this from occurring by typing in shutdown /a. And Windows tells us that the log off is canceled, and the scheduled shutdown has been canceled.

We mentioned earlier about using the format command to write a file system to a partition. But how do you create the partition to begin with? From the command line, you can use diskpart, which creates partitions from an available disk.

The diskpart command also has a number of different features inside of it, including the ability to do the format from within the diskpart command itself. You can also list, modify, or delete volumes from the diskpart command. So you do want to be very careful when working with diskpart or format, because both of those commands can easily remove data from your system.

Let’s run diskpart on my computer. I’ll type in diskpart. When I do that, it will tell me that what I’m about to do requires elevated permissions, and do I really want to run this program?

And we can say, yes, we do want to run it, because we do know what we’re doing, in this case. And you can see that we’re at a diskpart prompt on my Daedalus server. If I use the help command, you can see there are a number of options available for diskpart.

You don’t have to know all of these options for the A+ certification. But it is useful to know what options might be available if you needed to use the diskpart command. I’ll scroll down so we can use the list command, and see what options might be available by typing list.

I could list the disk. I can list partitions, volumes, or v disks. If I use the list command with disk, it will show me that this system has a single disk inside of it.

And Windows calls this disk 0. I do happen to know, on this disk are additional volumes. So I’m going to type list volume. And you’ll see on that individual disk are a number of different volumes available. And you can see how those particular volumes have been configured, and the file systems on each one of those volumes.

The winver command provides you with information about the version of Windows that’s running on your local system. This is especially useful when troubleshooting, because often, you’ll sit down at a system. And you’re not quite sure which version of Windows happens to be loaded on that system, especially if it’s a Windows version that has a lot of patches and you’re interested in knowing if this system has been patched or not.

You simply use winver at the command prompt. And you’ll get the dialog box in Windows that tells you more about that Windows system. If I run winver on this computer, you can see that it is a Windows 11 device, it’s running version 21H2, which is OS build 22000.675.

With this information I can determine if there has been any patches installed on the system. Or if I need to install a particular driver, I know exactly what operating system I need to look for so that I’m using the correct driver with the correct operating system. In this training course, we’re going to do a lot more with Active Directory and setting group policies so that you can manage remote Windows devices.

But for the purposes of this video, let’s talk about some commands the users can run to be able to perform some of these group policy updates. The first command we’ll look at is gpupdate, or forcing a group policy update. When an administrator creates a group policy that changes the configuration of one or many remote devices, you usually require that user to log out of Windows and log back in for that change to take place. But gpupdate command can allow the user to perform that update without having to cycle through the login process.

Before doing that, the user might want to run gpresult to see what the current configuration is for Group Policy on that particular device. And then, once you perform a gpupdate, you can run the gpresult again to see what the differences might be. For this example, I’ve moved to a Windows 10 device that is set up to be one of the users that’s in an Active Directory infrastructure.

This user, Rodney McKay, has logged in. And we’re the command prompt for their system. Let’s run a gpresult/r. This will compile all of the information about the current Active Directory configuration and show you all the group policy settings.

You can see, this is a member workstation, the operating system, version, and other details about this user. We also have information about the Active Directory configuration. This is user Rodney McKay, who’s in the user’s OU under the Atlantis OU in the Pegasus OU, and is part of the domain controller of SGC.local.

This user has two different objects that have been applied for Group Policy. One redirects folders, and the other maps drives during the login process. In the background, a system administrator has set up some new group policies that will change the configuration of all of the devices on the network.

One of these changes will be to add a new shortcut to the desktop of everyone’s computer. We could, of course, log out and log back in. Or we could use the gpupdate command, which by itself will take any changes to Group Policy and apply those, or if we want to apply everything in group policy, we can use the /force at the end so that everything is updated. When I hit gpupdate/force, you’ll see that it says that it is updating policy.

And if you look in the upper left, a new shortcut was added to the desktop that was created using group policy. If we then run another gpresult/r, we’ll get the same report that we had before. But you’ll notice that one of the options under Applied Group policy objects includes the original folder redirection and login map drives. But now, there is a new group policy that’s been added for desktop shortcut assignments. This allows us and the user to confirm that the changes that were made for group policy have been pushed down to our local machine and are currently in use.