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

Quick program access is important for productivity. Some of us have taskbars and start menus overflowing with shortcut icons. It's not an ideal situation, often pushing users to seek out taskbar alternatives like these multifunctional docks.

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.

command-prompt-tasks-path-variable

First, you have to create a new folder (such as C:\Shortcuts). This folder will hold the shortcuts that allow fast-access to any program on your system. Once created, we'll need to add that folder to the system's PATH environmental variable:

  • 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.

command-prompt-tasks-shortcuts

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

The label command offers a quick way to change the name of a drive on your system. It's so simple that there isn't much to explain about it. Just use it like so:

        label [drive:] [name]
    

For example, if I wanted to name my main drive "MakeUseOf", I'd run the following command:

        label C: MakeUseOf
    

Defragment Hard Drives

Modern file systems (e.g. NTFS) don't need to be defragmented as often as file systems of the past (e.g. FAT32), but it's still an important part of Windows maintenance, if you want to keep your system in tip-top shape. Be cautious with defragmentation of SSDs, though.

Though there are several excellent defragmentation utilities, you can still make do without them using the defrag command:

        defrag [drive:]
    

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:

        chkdsk [drive:]
    

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?

You can use the diskpart command (read: "disk partition") to eject the drive:

command-prompt-tasks-eject-drive

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.

Type

        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

A handful of tools enable a fast Windows search, but many of them are limited in that they only search through file names and not file contents. The findstr command is a simple way to achieve the latter, allowing you to locate files based on the text within those files.

command-prompt-tasks-findstr

This command is the most complex command on this list with over a dozen switches that alter how the search is performed. Too much to go over in a few paragraphs anyway, so here's a complete overview and a few examples to show how the command can be used.

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:

        assoc [.ext]
    

To clear the association of an extension:

        assoc [.ext]=
    

To set the association of an extension to another filetype:

        assoc [.ext]=[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.

Final Thoughts

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.

Plus, we've only scratched the surface. Make the command prompt even more useful by learning these important commands for all Windows users and reading over our command prompt cheat sheet. One more important task that ought to be mentioned is the ability to install software through the command prompt.

How often do you use the command prompt? Are you comfortable with it or does it intimidate you? Share your thoughts and questions with us in the comments below!