Don’t feel intimidated! The Windows command prompt is simpler and more useful than you expect. Graphical interfaces may be convenient, but sometimes it’s quicker to run a specific command to perform a specific task.
If you’ve never touched the Windows command prompt, or if you’ve given up on it due to issues in the past, we ask that you reconsider. If you still don’t like it, that’s fine and we won’t blame you. However, we think you might be surprised by what you can accomplish with just a few keystrokes.
Run Any Program Easily
Fortunately, there may be an answer that you hadn’t considered before. With a little bit of setup, you’ll be able to run any program that you want with a single command.
- Right click on My Computer and select Properties.
- Click on Advanced System Settings.
- Under the Advanced tab, click on Environment Variables.
- Under System Variables, edit the PATH variable. Add ;C:\Shortcuts to the end of the variable’s value (don’t forget the semicolon separator).
- Under System Variables, edit the PATHEXT variable. Add ;.LNK to the end of the variable’s value (don’t forget the semicolon separator).
- Click OK to close out of all windows.
Now that the environment variable is established, all you have to do is create shortcuts to your programs, place those shortcuts in the C:\Shortcuts directory, and rename them as one-word commands.
Now, whenever you open up a command prompt, you can run those programs using those shortcut names. The command prompt’s current directory won’t matter. These shortcut commands will work from anywhere.
Rename Local Drives
label [drive:] [name]
For example, if I wanted to name my main drive “innocentric”, I’d run the following command:
label C: innocentric
Defragment Hard Drives
That’s all. However, if you’d like a bit more diagnostic information while the defragmentation occurs, you can use the progress switch to print out progress to the prompt:
defrag [drive:] /U
And if you want as much information as possible, you can toggle the verbose switch:
defrag [drive:] /U /V
Monitor Hard Drive Health
The chkdsk command (read: “check disk”) is a diagnostic tool that scans through your hard drives and tests for potential issues like corrupted data or physical damage. It’s just as easy to use as the defragment command above:
Two useful parameters are the fix switch, which attempts to fix any encountered errors, and the recover switch, which will try to recover what it can if it encounters any bad sectors.
chkdsk [drive:] /F /R
Safely Eject External Drives
While drive ejection is as simple as right-clicking on the drive and selecting Eject, sometimes this isn’t possible. For example, you may be stuck in Windows Recovery with no other option than to use the command prompt. What do you do then?
When diskpart’s specialized prompt is ready, type
list volume to get a list of all drives currently recognized by your system. Take note of the drive’s ###, then type
select volume [###] according to the drive you want to eject. Make sure you only select drives that are marked “Removable” in the list.
remove all dismount to eject the drive and
exit to end the specialized prompt. The drive should now be dismounted and safe to remove.
If you have trouble getting the system to recognize the drive again, repeat the process up until you’ve selected the volume, then type
assign letter=[letter] to remount the drive. For example,
assign letter=I would mount it as an I: drive.
Search File Contents
This command is the most complex command on this list with over a dozen switches that alter how the search is performed.
Change File Associations
As you may already know, Windows associates particular file formats with programs so that those programs are used when said files need to be opened. The assoc command (read: “associate”) is an easy way to view and edit these file assocations.
Typing the command by itself will list all of the known file associations on your system. This can be useful for diagnostic purposes, otherwise it’s a bit too much information to digest at once. What it’s actually useful for is changing file assocations.
To view the association of an extension:
To clear the association of an extension:
To set the association of an extension to another filetype:
What is a filetype? For that you’ll need to use the ftype command, which lists all of the known filetypes on your system and which programs they’re associated with. So for example, on my system .TXT is associated as a txtfile and that filetype is opened using Notepad.
Yes, there are tools that can handle all of the above tasks, but these commands may come in handy if you ever find yourself stuck in a command prompt or needing to write a batch script.