We’ll go over some of the most basic, common uses
Earlier today I had to boot a client computer into safe mode and delete a virus via the command prompt because whenever Windows would load, the file would become locked and hence undeletable! There are several other reasons why you may have to use the command prompt in your life (though rarely), so it’s good to know how to navigate your way around!
If you have been meaning to learn how to use the command prompt in Windows, I’ll go through some of the basic commands that are performed most often. Just so everyone’s on the same page, you can get to the command prompt by going to Start and then click on Run and typing in CMD. In Windows 7, just click on Start and begin typing cmd. In Windows 8, you can just right-click on the Start button and choose Command Prompt.
You’ll now see a large black window with the cursor at the end of the path to your user profile in C:Documents and SettingsUsername or C:UsersUsername. So what to do now!? Well, since I can’t explain everything, you’ll probably want to end up using some of the help guides that are provided in MS DOS itself by typing in HELP and pressing Enter.
When you do that, you’ll get a list of all the commands you can use in MS DOS and a short description of what they do:
You can also find out more detailed information about the parameters and how to use each command by typing in the command name followed by a /?. For example, typing in CD /?, will present you with a quick tutorial on how to use the CD command:
As you can see from above, the MS DOS command CD displays the name of or changes the current directory. So if you wanted to change from the default user profile directory to the Windows System32 directory to delete a virus file, you would type in the following to navigate to that directory:
cd c:windowsystem32 and press Enter
You current directory at the prompt will now change to:
Now that you are in that directory, you may want to view all of the files and directories first, so you can type in the command DIR and press Enter. You’ll now get a giant list of all of the files and folders in that directory. You can type in DIR /? and see what parameters you can pass to it.
As you can see, you could type in DIR /P to give the list in a paginated format that you can browse through slowly. Or you could type in DIR /W to get the list in a wide format rather than one single column. The cool thing about DOS is that you can include several parameters for each command, so you could type in DIR /P /W and get a page-by-page view along with wide format:
So now that we have a list of files and folders, let’s continue with our deleting a virus example. If you want to delete a file, you would use the DEL command. Again typing in DEL /? will give you some useful info on the command.
To delete a file, we can simply type in DEL filename and that will delete the file. When you use the command this way, it won’t prompt you to confirm before deleting the file, so make sure you have typed in the correct file name. Also, you have to enter the file name with the extension, so it would be DEL Test.txt to delete that file. Also, if you need to delete a file that has spaces in the name, you have to use quotes like DEL “This is a test.txt”.
If you need to create or delete folders, you would use the MKDIR and RMDIR commands. It’s worth noting that if you try to delete a non-empty directory, you will get an error message. However, if you are sure you want to delete the directory and everything inside, you can use the RMDIR /S foldername command.
There are lots of other commands that you can use to do all sorts of stuff like copy files, print text files, change file permissions, etc. So if you can do most of this stuff in Windows using the GUI interface, then why bother with DOS, right?
Firstly, you never know when something bad will happen to Windows and you’re stuck in the command prompt because nothing else will load. Also, any command you type in the command prompt, like we showed above, can be saved into a file with a .BAT extension and run anytime by just clicking on the file or can be scheduled to run using the Windows Scheduled Tasks Control Panel applet.
So if you want to be able to routinely perform some simple actions on your computer, like copying files from one folder to another, just type the commands into Notepad and save the file with a .BAT extension instead of as a text file. Basically, you have to choose All Files for the File Type option and then type in the name like “MyFile.bat” with the quotes included.
Let me mention a couple of other commands that prove to be very useful very often.
The IPCONFIG command gives you information about your network cards, IP addresses and also lets you renew your IP address. My favorite is ipconfig /all, which will give you detailed information about each network adapter on your computer. You can then use this info to figure out your router IP address (default gateway) and whether or not you’re getting an IP address from a DHCP server.
Again, when you end up with hard drive problems, this command can prove to be very useful. DISKPART lets you administer the hard disks installed on your computer. You can do things like set a partition to be the active partition, assign a drive letter to a partition, shrink a disk, take a disk offline or online, etc.
System File Checker is really useful because it scans all protected system files and replaces incorrect versions with correct file versions. There will be a lot of times when certain system files in Windows have become corrupt and system file checker will fix them for you easily. You just run sfc /scannow and it will perform a scan and fix any issues. It does take quite a bit of time, but worth it if you’re having any kind of corruption issues.
A couple of other very useful commands that you might have to end up using are listed below:
- chkdsk – Verifies a hard disk or a floppy disk for file system integrity.
- copy – Copies files from one location to another. The destination defaults to the current directory. If there are multiple source files, the destination must be a directory or else you will get an error.
- fc – Compares two files or sets of files and displays the differences between them
- fdisk – Manipulates hard disk partition tables. When run from the command line, it displays a menu of various partitioning operations.
- format – Delete all the files on the disk and reformat it for MS-DOS. Use mostly for formatting floppy disks or other removable disks.
- scandisk – Disk diagnostic utility that is a replacement for the CHKDSK utility.
- netstat – Shows you all the current connections from your local computer to anything external.
That should hopefully get you up and running on how to use and navigate in the MS DOS command prompt! You can also check out this site that has a list of all commands you can use at the command prompt. If you have a question, please post a comment! Enjoy!