Section 14.1. Using the Command Line

The premise of the Command Prompt is simple enough: commands are typed, one at a time, at a blinking cursor. The commands are then issued when you press the Enter key. After the command has completed, a new prompt is shown, allowing you to type additional commands.

To run the Command Prompt, type:


at Start Search or in the Address Bar of Windows Explorer.

Some commands are fairly rudimentary, requiring only that you type their names. Other commands are more involved and can require several options (sometimes called arguments or command-line parameters). For example, you use the del command (discussed later in this chapter) to delete one or more files; it requires that you specify the name of the file after the command, like this:

del /p myfile.txt

Here, myfile.txt is the filename to be deleted and /p is an extra option used to modify the behavior of del (it requires confirmation before it will delete each file). The fact that this usage is not limited to internal command prompt commands (such as del) is what makes the command line (but not necessarily the Command Prompt application) such an important part of Windows Vista's design. For example:

notepad myfile.txt

is what Windows executes behind the scenes, by default, when you double-click the myfile.txt icon in Explorer. Notepad (discussed in Chapter 10) is effectively a "command" here. If you type the filename of any existing file at the Command Prompt, it instructs Windows to launch that file. This works for applications, Windows Shortcuts, batch files, documents, or any other type of file; the only requirement is that the file be located in the current working directory (see "cd or chdir," later in this chapter) or in a folder specified in the path (also discussed later in this chapter).

Specifying a filename as an argument when launching Notepad (such as myfile.txt in the preceding example) from the Command Prompt instructs Notepad to open that file. Throughout this book, you'll see references to a component's command-line syntax that documents these otherwise hidden features. Because every program and command has its own set of command-line options, it's best to get a feel for the way they work in general rather than trying to commit them all to memory.

If you've executed a command that takes a long time to complete, such as one that displays a great deal of information on the screen, you can usually interrupt it by pressing Ctrl-C.

Open the control menu of any open Command Prompt window (click the little icon in the top left of the window or press Alt-Space bar) and select Properties to customize the look and feel of the Command Prompt window (see Figure 14-1). An important option here is Layout Screen Buffer Size Height, which controls the number of lines kept in memory; this enables you to scroll up to view a history of your entire session. This is useful, for example, if you're looking at long directory listings. Note that this is not the same as Options Buffer Size, which contains a "most frequently used" list of typed commands; use the up and down arrow keys at the prompt to cycle through them, or press F7 to have an old-school character-mode menu pop up with your entire command history.

Figure 14-1. Setting options for the Command Prompt

Copy and paste operations are also possible at the Command Prompt, but not using the traditional keyboard shortcuts; Ctrl-X, Ctrl-C, and Ctrl-V won't work here. If QuickEdit is enabled (Properties Options QuickEdit mode), you can highlight text at any time with the mouse, copy it to the Clipboard by pressing Enter, and paste it by clicking anywhere in the window with the right mouse button. If QuickEdit is disabled (the default), right-clicking will display the Edit menu; select Mark to begin highlighting text and then go to Edit Copy or simply press Enter to copy the text to the Clipboard.

Finally, the prompt itself is usually accompanied by a folder name representing the current working directory. Note that the term directory is synonymous with folder and is used throughout this chapter only because it is customary when discussing the Command Prompt.

See "Command Prompt," later in this chapter, for more information on the cmd.exe application and its command-line parameters. Of special interest is the /e parameter, which enables or disables "command extensions," which are additional features documented throughout this chapter.

Part II: Nutshell Reference