Industry guru Dave Taylor offers free tech support on a wide variety of technical and business topics, including HTML, Apple iPhone, online advertising, Cascading Style Sheets, Web design, management, Unix, Linux, search engine optimization, online dating, Mac OS X, shell script programming and Microsoft Windows.

How do I use the Windows command prompt line?

Now I know how to open a command prompt in Microsoft Windows, how do I perform common tasks in a command prompt? Can you show me some command prompt basics and perhaps something cool I can do to impress my friends?

Dave's Answer:

You already know how to open a command prompt, which is required in order to run certain commands and prompts in Windows.

When you think about the Windows command prompt, just imagine that you're traveling back in time and are working on a computer that was state of the art back in, oh, the early 1990s, maybe, or even a bit earlier. No mouse, no icons to click on, no windows, no pretty pictures. Just text. You type, the computer responds. That's it.

Here, let me remind you of what it looks like...

command prompt

Here are some tips and tricks to help you get more comfortable with the command prompt environment.

First, read how to copy and paste in a command prompt window, which was worth a separate article unto itself. You can't be comfortable with a Windows utility until you know how to copy and paste with it.

Here's a simpler trick: Re-entering a command without having to type it again. Type the command "ipconfig" in a command prompt and you'll see this output, which includes your computer's IP address:

command prompt ipconfig output

To enter the command "ipconfig" a second time, without having to type the command again, hit the up-arrow key on your keyboard, and the word "ipconfig" will reappear in the command prompt.

command prompt ipconfig reentered

The command prompt has a memory of all the recent commands that you typed in (up to 50 commands, by default), so that you can iterate back through your recently entered commands by hitting the up-arrow key repeatedly. For example, after typing "ipconfig" and hitting Enter, try typing "ver" and hitting Enter. (You should see "Microsoft Windows XP [Version 5.1.2600]" or something similar depending on your version of Windows.) Hit the up-arrow key, and the "ver" command will re-appear since it was the last command you entered. But hit the up-arrow key again, and the "ipconfig" command will re-appear. (This buffer of recently-typed commands gets erased when you close the command prompt, so if you close the command prompt window and open another one, hitting the up-arrow key will not recall commands that were entered in the previous command prompt window.)

By default, a new command prompt window opens with a "working directory" of
C:\Documents and Settings\<username>
where <username> is the username that you used to sign in to Windows -- on my Hewlett Packard computer, this is HP_Administrator, as seen in the command prompt pictures above, where my working directory is
C:\Documents and Settings\HP_Administrator
If your computer signs you in automatically every time you start it up, you might have forgotten that you even have a Windows username, but you do have one! (And by the way,
"C:\Documents and Settings\HP_Administrator"
is known to the hard-core old-schoolers as a directory, although you might know it as a folder.)

Sometimes, in order to run a command that applies to a specific file on your computer, you need to change your working directory to the directory containing that file. For example, consider the "tree" command, which displays a list of all the directories within a directory, and a list of sub-directories within each of those directories, etc. I want to display the tree of all subdirectories within the directory
C:\Program Files\Common Files\Adobe\TypeSupport

There are two ways that I can do this. The first way is to enter the full path to the directory in the command. "C:\Program Files\Common Files\Adobe\TypeSupport" is the "full path" to the directory. However, if I try entering "tree" followed by the full path to the directory:
tree C:\Program Files\Common Files\Adobe\TypeSupport
I get an error that doesn't make much sense:

command prompt full path no quotes error

This is because the command prompt considers whatever comes after the "tree" command to be the first argument to the tree command -- basically, the thing that the tree command "operates on" -- however, it stops reading at the first space, after the word "Program". Then it gets confused by the next glob of characters, "Files\Common". In order to get the "tree" command to take the entire full path as an argument, we need to put quote marks around the full path:
tree "C:\Program Files\Common Files\Adobe\TypeSupport"
and this works:

tree full path output

The second method would be to change the working directory to
C:\Program Files\Common Files\Adobe\
before running the command on the directory "TypeSupport". In a command prompt, the command to change directories is "cd", followed by the directory you want to change to. As before, when entering the full path to the directory you want to change to, you have to use quote marks so that the entire path is treated as a single argument:

cd to adobe directory

Once you have changed the current directory to
C:\Program Files\Common Files\Adobe\
you can enter the command:
tree TypeSupport
Because you are already in the "Adobe" directory, the word "TypeSupport" by itself automatically refers to the "TypeSupport" directory that is inside the "Adobe" directory, and so the full path is not needed:

tree command relative

One final note about changing directories using "cd". If you want to switch to a directory that begins with a different drive letter -- for example, if your working directory is "C:\Documents and Settings\" but you want to change to the directory "D:\" -- then the "cd" command won't work:

cd still on c

Instead, to change to a different drive, just type the drive letter by itself, followed by a colon:

change to d

That will switch your working directory to a new drive letter.

And that's it! With these basics, if you encounter any instructions page telling you to run a certain command "within a command prompt", but that doesn't explain the basics of navigating inside a command prompt, these tips will probably take care of 90% of the situations that you'll run into.

Bennett Haselton is a technology blogger who will gladly buy you a latte if you let him talk to you about how to bypass K9 Bluecoat web filters.



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon    

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

O how I love the DOS command prompt, the geek that I am.

These days the only use I have for it for looking up a mac address for a wireless card.

ipconfig / all

I'm glad Microsoft has kept the DOS command prompt in all the windows versions for us old school people.

Posted by: Rob Abdul at November 10, 2009 3:34 AM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Uniblue: Free Virus Scan

Follow me on Twitter @DaveTaylor

Search
Find just the answers you seek from among our 2300+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Book Links
© 2002 - 2009 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.