Earlier today I had to boot the client computer in Safe Mode and remove the virus via the command line, because whenever Windows was booted, the file was blocked and therefore could not be deleted! There are several other reasons why you may need to use the command line in your life (albeit rarely), so it’s good to know how to navigate!
If you wanted to learn how to use the command prompt on Windows, I will cover some of the basic commands that are executed most frequently. To keep everyone on the same page, you can go to the command prompt by choosing Start, then clicking Run and typing CMD. In Windows 7, just click Start and start typing cmd. In Windows 8, you can simply right-click the Start button and select Command Prompt.
Now you will see a large black window with a cursor at the end of your profile path username in C: Documents and Settings Username or C: Users Username. So what to do now !? Well, since I can’t explain everything, you probably want to use some of the reference guides that are provided in MS DOS itself by typing HELP and pressing Enter.
When you do this, you will receive 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 information about parameters and how to use each command by entering the command name followed by a /?. For example, typing CD /? Will give you a quick guide to using the CD command:
As you can see from above, a CD with with MS DOS commands, displays the name or changes the current directory. Therefore, if you want to change from the default user profile directory to the Windows System32 directory to remove the virus file, you must enter the following to change to that directory:
cd c: window system32 and press Enter.
Your current directory in the query will now change to:
Now that you are in that directory, you can first view all files and directories, so you can type DIR and press Enter. Now you will get a huge list of all files and folders in that directory. Can you enter DIR /? and see what parameters you can pass to it.
As you can see, you can enter DIR / P to get the list in a paginated format that can be viewed slowly. Or you can enter DIR / W to get the list in a wide format rather than a single column. The great thing about DOS is that you can enable multiple options for each command, so you can type DIR / P / W and get a page view along with a wide format:
So now that we have a list of files and folders, let’s proceed with removing the virus example. If you want to delete a file, you must use the DEL command. Typing DEL / again? will provide you with useful information about the team.
To delete a file, we can simply enter DEL filename and the file will be deleted. When you use the command this way, it will not prompt you for confirmation before deleting the file, so make sure you enter the correct file name. In addition, you must enter a filename with an extension to delete that file using DEL Test.txt. Also, if you need to delete a file with spaces in the name, you must use quotation marks, for example DEL “This is test.txt”.
If you need to create or delete folders, you must use the MKDIR and RMDIR commands. It’s worth noting that if you try to delete a non-empty directory, you will receive 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 many other commands that you can use to do all sorts of things like copying files, printing text files, changing file permissions, etc. So, if you can do most of these things on Windows using a graphical interface, then why bother with DOS, right?
First, you never know when something is going to happen to Windows, and you are stuck at the command line because nothing else loads. In addition, any command that you enter on the command line, as we showed above, can be saved to a file with the .BAT extension and run at any time by simply clicking the file, or you can schedule the launch using the Windows Scheduled Tasks Control Panel applet.
Therefore, if you want to be able to regularly perform some simple actions on your computer, for example, copy files from one folder to another, just enter commands in Notepad and save the file with the .BAT extension instead text file. Typically you will need to select “All Files” for “Save as type” and then enter a name like “MyFile.bat” with quotation marks.
Let me mention a couple more commands that are very often very useful.
The IPCONFIG command provides you with information about your network cards, IP addresses, and also allows you to update your IP address. My favorite is ipconfig / all, which will give you detailed information about every network adapter on your computer. Then you can use this information to find out the IP address of your router (default gateway) and whether you get the IP address from the DHCP server.
Again, when you are having problems with your hard drive, this command can be very helpful. DISKPART allows you to manage the hard drives installed on your computer. You can make such a partition active, assign a drive letter to it, shrink the disk, take it offline or online, etc.
The System File Checker is really useful because it scans all protected system files and replaces the wrong versions with the correct file versions. There will be many times when certain system files in Windows turn out to be corrupted and the System File Checker will fix them easily. You just run sfc / scannow and it will scan and fix any issues. It will take quite a while, but it will be worth it if you run into any damage issues.
A couple of other very useful commands you may need to use are listed below:
- chkdsk – Checks the hard disk or floppy disk for file system integrity.
- copy – Copies files from one location to another. By default, the current directory is used as the destination. If there are multiple source files, the destination must be a directory, otherwise you will receive an error message.
- 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 files on the disk and reformat it for MS-DOS. Used primarily for formatting floppy disks or other removable drives.
- scandisk – Disk diagnostic utility that replaces the CHKDSK utility.
- netstat – Shows all current connections from your local computer. computer to everything external.
Hope this helps you learn how to use and navigate the MS DOS command line! You can also visit this site for a list of all the commands you can use on the command line. If you have a question, please leave a comment! Enjoy!