The Windows Command Prompt: Simpler And More Useful Than You Think

cprompt   The Windows Command Prompt: Simpler And More Useful Than You Think When most people think of the old DOS command prompt window – that archaic, lingering vestige of computer days gone by – they think of those simple commands that nearly everyone learned if they had to use a computer during those early days.

Folks learned how to see a directory content with DIR or how to navigate from one directory to the next with CD. Not all commands were very intuitive, and of course before long we had that wonderful graphical user interface of Windows 3.1 (still my all-time favorite) and beyond.

One would thing that with the advent of the graphical user interface, there would be no need for using any sort of command-line activities – yet the CMD tool lingers on from one generation of Windows to the next.

The commands haven’t always stayed the same, in fact some have been trashed while other newer commands came along, even with Windows 7 in fact. So, why would anyone want to bother clicking the start button and typing “CMD” into the Run field? Let me show you why.

The Magic of the Windows Command Prompt

Windows is without a doubt filled with lots of features and tools for you to do all sorts of things like run disk drive diagnostics, search through thousands of files across multiple directories, and copy/paste everything from pictures and documents to files and directories.

Yes, the interaction of Window and Mouse have come a long way, but do you always remember where to find what you need to do? Do you always recall, quickly, where you need to click?

Let’s take a look at several very simple but extremely useful CMD commands that you can use in Windows 7. The following are 13 commands that will save you the time and headache of having to click, click and click. Instead, click Run, “CMD” and then type your command. Done.

Before we get started, find cmd.exe in C:/windows/system32/, create a shortcut and place it on your desktop. Then right click it and select properties.

command1a   The Windows Command Prompt: Simpler And More Useful Than You Think

Click on the shortcut tab, click on the “Advanced” button, and select “Run as administrator”. For the commands I’m going to share, double click this shortcut to enter the command prompt, so that you can be sure you have admin rights.

1. ASSOC – Associate File Types

So, you went to open up a text document and Windows kindly asked you what program you want to use. Just this once, you’re testing a new text editor, so you click on that selection and forget to uncheck the box that makes this your default selection.

Now, every time you go to open a text file, it uses that new text editor instead of notepad. Do you remember how to set it back?  Not many people do. Instead, open up a command prompt and type the “ASSOC” command.

command1   The Windows Command Prompt: Simpler And More Useful Than You Think

This will show you all file associations related to all of the registered file extensions on your system. This is a pretty extensive list, but it gives you everything in a single shot, which is really convenient.

To see the same thing in the Windows GUI, you have to go to Control Panel, click on “Default Program” and the link to associate file types.

command2   The Windows Command Prompt: Simpler And More Useful Than You Think

You can use the ASSOC command to associate any file extension with whatever registered file types you have on your system. However, I don’t commonly use it for this – my thing is to quickly free up a file extension that I accidentally associated with some other program. To do this you just type in the file association assignment and leave the right side of the command blank.

command3   The Windows Command Prompt: Simpler And More Useful Than You Think

“ASSOC .txt=” tells Windows that the next time I double click on any .txt file, to ask me what program I want to use to open the file. This gives me the opportunity to reassign the file association if I like.

2. CIPHER – Encryption Command

Yes, you have the ability to encrypt and decrypt files and entire directories from the command prompt, but keep in mind that Cipher (EFS) is not supported (fully) on Windows 7 Starter, Home Basic or Home Premium.

If you have any other version, you can run the CIPHER command to enable a directory as an encrypted directory. Any new files you add to that directory will also be encrypted.

command4   The Windows Command Prompt: Simpler And More Useful Than You Think

As you can see, my system doesn’t support encryption, but if it did you would see the result at the bottom stating that the 1 directory was encrypted.

If you’d like to play around with this command on your machine, make sure to check out Microsoft’s explanation of how EFS works.

3 & 4. MORE and CLIP – Making Command Output Useful

The next few commands are very simple, but I feel compelled to review them because they come in handy so often, and not everyone knows about them. While you’re going through your various commands and you get huge lists of output – such as a directory listing – it can be really nice to record that output.

You can record the results of a command right to the clipboard using the CLIP command. Just type “| clip” after the command.

command5   The Windows Command Prompt: Simpler And More Useful Than You Think

Now, in the example above, I can go into any other application like Excel, Word or Notepad, and just paste that output.

command6   The Windows Command Prompt: Simpler And More Useful Than You Think

It is one of the fastest and easiest ways to obtain the complete listing of files in a directory, driver or hardware details about your computer, or any other information that you can pull from your system using any Windows command.

If you instead follow a command by “| MORE”, it will just keep the output on the screen, but instead of scrolling like mad up the screen faster than you can read it, it’ll stop when the screen is full and wait for you to press a keyboard key before scrolling again.

5. COLOR – Have Some Fun

Okay, so we’re not all work and no play here. If you want to stand out, play around with the color scheme of your Windows 7 command window by typing in the color command followed by a two digit number. The first hex digit is the background, and the second is the foreground.

command7   The Windows Command Prompt: Simpler And More Useful Than You Think

Just type “color /?” if you can’t remember the codes. Just black and white can get boring, so mix it up a little! If your friends ask you how you did that, just tell them that you’re a world class hacker.

6. DRIVERQUERY – Get Your Driver Information

Working in IT, there is nothing more frustrating than working on communicating with a device, only to learn that the device driver is wrong, or the version is out of date. That headache can be avoided by running the DRIVEQUERY command to get a full list of installed drivers on your system.

Just output it to the clipboard with the CLIP command, or output it to a file with something like, “DRIVERQUERY >> mydrivers.txt”

command8   The Windows Command Prompt: Simpler And More Useful Than You Think

The “>>” operator is actually an “append to file” command and it will create the text file and add the details. If the file exists, it’ll append the info at the end. Use “>” if you want it to wipe any old data and create a new file.

7. FC – File Compare

Another really useful command – especially if you’re a writer or a programmer and often find yourself trying to find out what changes took place to a file – is the FC command.

In my example below, I had two self-written biographies and wasn’t sure which was the most recent, so I type “FC /L ryanbio.txt ryanbio2.txt”.

This does an ASCII comparison and actually outputs the sections of text in each file that are different.

command9   The Windows Command Prompt: Simpler And More Useful Than You Think

This isn’t the sort of useful feature many people associate with Windows command prompt command – but there it is. I’m not saying it’s a very new or exciting command, but it is a command that can make using the Windows command prompt a much faster and more effective way to get a job done than trying to figure out how to do it in some application.

8 & 9. DEFRAG and CHKDSK – Useful Maintenance Tools

Some people swear that a regular defrag of your hard drive will keep it healthy and will make everything run more smoothly. Other people say the efficiency difference is negligible.

I say, if it’s important to you, then run the command. In fact, just set up a weekly or monthly scheduled task to get the job done and you’ll never even have to think about it again.

As you can see from the example below, I use “DEFRAG C: /U /V”.

command10   The Windows Command Prompt: Simpler And More Useful Than You Think

The /U switch prints the progress of the defrag to the screen, and /V makes that output verbose. Obviously if you’re running a scheduled task in the background, you wouldn’t bother with that.

Another important maintenance command I run regularly is CHKDSK to monitor the health of my hard disk. I run “CHKDSK c: /F /R”, which will check the C: drive for any problems. If if finds errors it will fix them thanks to /F, and it’ll try to recover readable information from bad sectors thanks to /R.

10 & 11. HOSTNAME and IPCONFIG – Network Troubleshooting Tools

So you’re on the phone with IT and they need the hostname of your computer, what do you do? Yes, you could open up File Explorer, right click on the My Computer and check the Properties, or you can visit “System” in the Control Panel.  If you want to be super-fast though, just open up your command prompt and type in one word – “HOSTNAME”.

Done.

I’m sure lots of IT folks are rolling their eyes out there with the mention of IPCONFIG. Why? Well, because it’s one of the first commands that IT techs cut their teeth on. It’s the fastest way to check the IP address and MAC address of a machine, as well as the current state of the network adapter.

command11   The Windows Command Prompt: Simpler And More Useful Than You Think

It is also a real life-saver in some situations. I can’t count how many times I’ve had friends struggling with Internet connection issues, and doing a quick “IPCONFIG /RELEASE” followed by “IPCONFIG /RENEW” wipes the slate clean (obtains a new IP and therefore a “fresh” Internet connection from the ISP) and solves all their problems.

12. Function Keys Are Your Friend

Another well protected secret about your command prompt is that Function Keys also have a purpose in Windows 7. While you’re typing one command after another, you can quickly navigate through commands with the following function keys:

F3 – Shows you the last executed command

F4 – Deletes any text you’ve just entered

F7 – Displays the entire list of recent commands you’ve used

F9 – Lets you select one of the commands from the F7 list to paste to the command line

It would have been really nice to have those function key features in the earliest days of DOS, when we had to type and retype commands if there were typos or mistakes. These days, you can whip out commands much faster than you could ever hope to navigate through various windows with point-and-click.

13. TREE – The Powerful Directory Visualizer

I think the coolest command that I stumbled upon is the “TREE” command. This simple and fast command will output an entire visual map of the directory structure, starting at the path location you define.  This is definitely one that you want to output to a text file.

In the example below, I used the command “TREE /a >> treeresults.txt”.

Since I was already sitting in “C:/Owner/” when I typed the command, it started drilling down through all of the directories in the “Owner” folder, and output the entire structure in an ASCII graphic (thanks the the /a switch).

command12   The Windows Command Prompt: Simpler And More Useful Than You Think

So, there you have it – 13 simple yet powerful commands that can make your computing experience a lot more efficient. And if you want to get a little creative, you could try your hand at writing batch files that incorporate several of them together!

Did I convince you to try out the Windows command prompt for the first time? Were there any commands listed here that were new to you? Share your thoughts and your own CMD tips in the comments section below.

Image Credit: Command Prompt via Shutterstock

Check out more about:

The comments were closed because the article is more than 180 days old.

If you have any questions related to what's mentioned in the article or need help with any computer issue, ask it on MakeUseOf Answers—We and our community will be more than happy to help.

42 Comments -

0 votes

Igor Rizvi?

I lvoe workign with cmd, great article!

0 votes

Mike Vaz

Good things to know!

0 votes

Paul Harris

When using the command prompt, typing cd.. takes you back one directory.
Typing cmd /? list lots of information.
Typing /? after a command ….say defrag or chkdsk will list all the options.

Be careful, very careful, when typing commands; you could mess up your system and have difficulty restoring it.

0 votes

Ryan Dube

Very good tip and true – that is one of the things about using commands, it is sometimes a little too easy to fat-finger something and cause some major problems. Thanks for the warning.

0 votes

James Graham

I have found over the years in working in IT departments that the GUI has cause many more ‘oops’ than the command line. One of the reasons I’ve found it to be my friend. Thanks for this article, found a few gems in here!

0 votes

neonblade

Enjoyed the article, brings back memories of my DOS days.
I like using DEFRAG from the command prompt in Windows 7, as I miss the Visual progress indicators from earlier Versions of the OS.

0 votes

Ryan Dube

I agree. I suppose if someone was very ambitious they could write some kind of Windows script that launches the defrag command, outputs to a file and then actively reads that file as it’s being created. I don’t even know if that’s possible but it sounds interesting. :-)

0 votes

Scutterman

I think the visual indicators went due to increasing disk sizes. When you had 100MB disks, it didn’t take a large output to display the clusters, but when you have 500GB, or even 1-2TB, that’s a whole lot of clusters.

0 votes

Scutterman

I use the “ping” command to test network connectivity. I can usually use it to tell whether a site is being slow, or my connection, and if my connection has completely dropped out, ping will sometimes bring it back up. I’ve also had ping inform me of DNS issues before.

0 votes

Pedro Oliva

great article… so useful thanks :)

0 votes

Lee

Another neat thing is that all of these can be put in shortcuts.
Just make a new shortcut and set the location to:
cmd.exe /k

0 votes

Ryan Dube

Cool tip – thanks Lee!

0 votes

Ravi Meena

how about some command for printing files with printers, creating bat files and automating tasks. i have been doing a little in my office but would like to see other people’s works.

0 votes

Ryan Dube

Thanks Ravi – search MUO for “command” or “cmd”. We’re written a lot of articles on the topic and I know in particular I’ve written a bunch on bat files and windows scripts that you may find helpful. Like you, I’d love to read about scripts that others have written.

0 votes

Austin

Cool, I always find myself using cmd in Windows occasionally, usually just to use handy programs like ffmpeg or youtube-dl that I use in Linux, but need to use for whatever reason in Windows. How does the standard cmd compare to Powershell? http://en.wikipedia.org/wiki/Windows_PowerShell

I still prefer bash though :)

0 votes

Ryan Dube

Austin – I recently attempted to teach myself PowerShell and realized that the complexity would require too much of my time at the moment. With that said – it looks like an amazing/powerful scripting language, but it’s a lot different than the cmd scripts that we’re used to, that’s for sure.

From what I hear, Powershell is here to stay, so it’s worth learning, for sure.

0 votes

James Graham

I’ve just taken up PowerShell scripting at work for admin functions, etc. I think I’m lucky that I never got the hang of VB or BASH, etc as this is a bit of a different animal <– but it is incredible what it can do. it's also nice that they have setup some common aliases so you can use 'get-help' or 'man', 'get-childcontent' or 'dir' or 'ls', etc.

0 votes

Luke Brannon

I used to use CMD a lot on my IT course and it was great when sorting out computer networking problems however I don’t get round much to using it in everyday life now :(

0 votes

imad

Great article. Even with windows7, we can never give up cmd because it is so useful and convenient. Just to highlight some of the other commands like ping, fdisk /mbr, format and dos prompt is very useful for running some old ms-dos programs. Also there is a search for text within files and directories.

0 votes

Ryan Dube

Definitely – there’s something to be said for the convenience of just popping open a command window and getting the job done, versus point and click-click-clicking…

0 votes

Alan Wade

A few more tricks with the command prompt window that I wrote about in another forum.
To change the default settings, right click on the icon in the top left hand corner and select ‘Defaults’.
In the window that opens click on the ‘Font’ tab.
Now by clicking on the different font sizes you will see in the little preview window the Command prompt window changing. It will alter to the font size you choose. Here you can select one of the three available fonts if you want to change it.
Click on the ‘Layout’ tab next now the trick with this screen is to decide how big or small you want the window to be first.
For this tutorial I have the window size set to 80 characters wide and 20 rows high.
With the buffer size, if I set it smaller then the window will reduce to the same size.
If I set it higher then you will have scroll bars on the window.
If I set it the same size then once the window is full with text, it will disappear from the top of the window as shown in the screenshot, so you must figure out what sizes suites your needs.
If you uncheck the ‘Let system position window’ box then you can set the window to open where you want it to.
Finally the ‘Colors’ tab.
Here you set the screen text and the background colours and you can change your popup window’s text colour and background here.
Press F1 or the Right Arrow key to retype the last command, one character at a time.
Press the Up Arrow key to cycle through the last commands entered.
Press F3 to retype the entire last command you entered.
Press F7 to open a popup menu, from which you can select the previously entered command available in the buffer. Use the arrow keys to move up and down in the list and press Enter to select a command. To close the popup menu without selecting a command, press Esc.
Press F9 to select a command by number. The numbers are the same as seen in the popup menu accessed using F7; however, the numbers are not displayed. To check the numbers for the command, press F7 again and then press Esc to close that popup menu.
To select a command enter the number for the command and press Enter. To close the popup without entering a number, press Esc.

0 votes

Ryan Dube

These are excellent tips Alan – thanks so much for posting them. I’ve saved them in my personal notebook of cmd notes. :-)

0 votes

Rizwan Saudagar

Useful info.. Thanks for article..

0 votes

vineedcool

nyc info on cmd ,,,

0 votes

Russ

“start .” is a useful command for easily switching back and forth between the command prompt and windows explorer. It simply opens windows explorer in the current working directory.

0 votes

Ryan Dube

Sweet – nice tip Russ. I actually didn’t know about that one!

0 votes

Joe Golla

Great article, it comes in the wings of needing to PIPE a directory listing to a txt file and import to a spreadsheet for sorting. (dir > print.txt)

0 votes

Ryan Dube

I’d think there’s a way to send it to txt file and then kick off a windows script that parses it into csv format? I’ve written such scripts before but not specifically for command output files. Would be a fun project though.

0 votes

Sushil Kathpalia

some of them are known but file comparing, TREE,CIPHER and file associates unknown to me..
So i would try all these commands…

0 votes

Evan Spangler

CMD is very useful for IT techs, too.

0 votes

Rigoberto Garcia

Great article Ryan. We use some. Bat in our daily operations to automate some tasks (the latter was used. RoboCopy bat with a task of Windows). Share this information with my colleagues. Thank you very much …

0 votes

Timothy Liem

still less powerful than Linux’s terminal for sure.

0 votes

Anandu B Ajith

Good things to know!

0 votes

Alex Livingstone

I love the cmd, great article.

0 votes

Sampath Widushan

Wow…nice post Ryan..this was very useful…and i didn’t thought that cmd was this much capable of doing handy work..thank you very much.

0 votes

sampath widushan

this is nice..

0 votes

JayF

I never throw away my old DOS manuals, either in book form or digital. They DO come in handy when all else fails. I’ve forgotten how old my copy of “Mostly Windows with just enough DOS” is — but it sure came in handy when Windows 7 started acting up! I also have manuals for other programs like Visual Basic and Linux.

0 votes

Ryan Dube

I agree…I am hoping against hope that CMD never goes away or gets completely and totally replaced by PowerShell.

0 votes

Sonuva Jack

cool

0 votes

Jerry

I use the command prompt for all sorts of things. Guess its because I cut my teeth on Unix! Anyway, I’ve found a limitation that is frustrating:

What I really want to do, is exactly like what I can do in unix (eg. in the bash shell), but in the Windows command shell.

e.g. in bash I can do this:

echo “The quality of mercy “\
> “is not strain’d. “\
> “It droppeth as the gentle rain”\
> “from heaven.”
The quality of mercy is not strain’d. It droppeth as the gentle rain from heaven.
jerryb1@ubuntu:~$

Can I do the same in the Windows shell? That is, can I start the echo command with one phrase, then continue it to the next line and the next and the next?

Here’s another example. Say I want to copy several files into one file. Copy let’s me do this:

copy foo+bar baz

Now, consider a case where the filenames are long. For readability, I’d like to do this:

copy
“this is the first file with a long name” +
“this is the second file with an even longer name”
“this is the concatenation of the first and second files”

Can this be done in the standard Windows shell? If so, what would I type for the ?

0 votes

Jerry

Oops. didn’t know it wouldn’t preserve my formatting. Let’s see if this works:

What I really want to do, is exactly like what I can do in bash, but in the Windows command shell. 

e.g. in bash I can do this:

echo "The quality of mercy "\
> "is not strain'd. "\
> "It droppeth as the gentle rain"\
> "from heaven."
The quality of mercy is not strain'd. It droppeth as the gentle rain from heaven.
jerryb1@ubuntu:~$

Can I do the same in the Windows shell? That is, can I start the echo command with one phrase, then continue it to the next line and the next and the next?

Here's another example. Say I want to copy several files into one file. Copy let's me do this:

copy foo+bar baz

Now, consider a case where the filenames are long. For readability, I'd like to do this:

copy 
"this is the first file with a long name" + 
"this is the second file with an even longer name" 
"this is the concatenation of the first and second files"

Can this be done in the standard Windows shell? If so, what would I type for the ?
</pre
0 votes

Saad

cool article , goold old DOS days, i use MEMMAKER command to increase my free memory.