Undocumented Command Prompt Tips

Learn NT command prompt features that resemble those of UNIX and OS/2

The Windows NT command prompt has many useful function keys and other features. Administrators who migrate to NT from UNIX or OS/2 will like these features because they emulate UNIX and OS/2's command prompts, and they streamline daily tasks. Many of the features I discuss are not documented elsewhere.

Customizing the Prompt
You might not realize that you can customize many NT command prompt options. You can change the command prompt window's default color and title; options such as the Command History, QuickEdit Mode, and Insert Mode; and layout and buffer options.

Colors and titles. Users commonly change the prompt window's default color. Start a command prompt, select the Control menu (click the MS-DOS icon in the top left corner, as Screen 1, page 168, shows), and select Properties. You can select the color of the text, background, and dialog boxes. After you mix your palette, click OK to apply the changes. The dialog box asks whether you want to apply the changes only to the current window or to the shortcut that started the window. If you want to apply your custom settings as the default when you start a command prompt, modify the shortcut.

You can also change the default colors directly from a command prompt. Go to a command prompt and type

color <attr>

The attr option is the foreground and background color attributes, written as two hex digits. The first hex digit specifies the background color, and the second digit specifies the text color. For a list of color attributes, go to a command prompt and type

color /?

To revert to the default colors, execute the color command without entering options.

You can use the title command to change the title of a command prompt window. The command prompt window's default title is the same as the label of the icon you used to start the prompt (i.e., Command Prompt). Sometimes you have multiple command prompts open. You launch multiple command prompts with one icon, so the command prompt windows have identical titles. Changing the titles lets you differentiate among the prompts. To change the title permanently, edit the icon's label. Right-click the icon, select Rename, and enter the title you want. For short-term changes, use the title command. Go to a command prompt and type

title <string>

General options. Screen 2 shows the settings on the Options tab of the Command Prompt Properties dialog box. The following items are the most useful: Command History, QuickEdit Mode, and Insert Mode.

In the Command History section, set the Buffer Size to the number of old commands that you want in the history. You can use the up and down arrows and the F7, F8, and F9 keys to recall commands in the history buffer. You must close and reopen the command prompt for a change in the buffer size to take effect. To eliminate duplicates, select the Discard Old Duplicates option. The command history is valid only while the command prompt is open. If you close the command prompt, the command history disappears.

The QuickEdit Mode lets you copy and paste text from the command prompt without using the control menu. Dragging your mouse over the text you want to copy highlights a rectangular shape. In most Windows applications, when you highlight part of a line and pull the mouse down, the highlighting automatically stretches to the end of the line. In the QuickEdit Mode, the highlighting extends only to the corners of the drag rectangle. You can then copy the text to other Windows applications.

The command prompt's default setting is overtype mode. If you want to set the default for inserting text at the prompt rather than typing over the text that is already there, select the Insert Mode option. To temporarily use the overtype mode from the command prompt, press the Insert key once. Press Insert again to revert to insert mode. This feature works regardless of your default setting.

Layout and buffers. Users often overlook NT's screen buffer, because it is not readily apparent. To set screen buffers, go to the Command Prompt Properties dialog box and select the Layout tab. By default, the screen buffer height and window height are 25, so you cannot scroll. To enable a longer buffer, set the screen buffer height to a larger number, as Screen 3 shows. You can also set the screen buffer width, window width, and window position.

Function Keys
Certain function keys are engrained in our minds from the DOS days. Many function keys perform the same action in NT as they did in DOS. Table 1, page 170, lists the function and related keys available at the NT command prompt, as well as the actions they perform. I will explain the less obvious function keys, and the keys I find particularly useful.

F2: Character to copy to. The F2 key is handy for repeating parts of lengthy or complex command lines. You can use F2 to copy the current command in the history buffer to the command prompt, up to the first occurrence of the character you specify. Press F7 to see the current command. You can use the up and down arrow keys to change the current command.

Suppose the current command in the history buffer is cd "\program files\plus!", and you want to move one directory level up to the NT directory. Directories with spaces in their names are cumbersome to type because they require quotation marks. To save time, perform the following steps. Press F2 and enter


to copy the line up to but not including the first p. The command line then contains cd "\. Press F2 again and enter


to copy the line to the next occurrence of p. The command line then contains cd "\program files\. To complete the command, type

Windows NT"

F4: Character to delete up to. The F4 key is a quick way to delete characters to the right of the cursor. Suppose you enter a lengthy path to change your directory to. As you execute the CD command, you realize that you haven't created the directory. You can recall the CD command with the long path, place the cursor at the beginning of the line, use F4 to delete up to the path, and enter the MD command to create the directory.

For example, the original CD command is C:>CD \WINNT\SYSTEM32\
INF\TEMP. To bring back the command, press the up arrow. Press the Home key to move the cursor to the beginning of the line. Press F4 and then press the spacebar to delete the command, up to but not including the space. The command is then C:> \WINNT\SYSTEM32\INF\TEMP. Make sure you are in insert mode, enter


and execute the command (i.e., C:>MD \WINNT\SYSTEM32\INF\TEMP).

In this simplified example, you can just as easily use the delete or backspace key to remove the CD command. However, F4 saves time when you need to delete a long string.

F7: Show command history. If the command history is long, you'll find it inconvenient to go through old commands individually. To view the entire list, press F7. You'll see a pop-up window such as the one in Screen 4. You can use the up and down arrows to move through the list of commands, or you can use Page Up and Page Down to scroll faster. You can press Esc to cancel the list without taking action.

Press Enter to execute a highlighted command. The command you execute then becomes the current command in the history buffer. Thus, subsequent actions that relate to the history start from this command.

F8: Show previous command with search capability. If you have nothing at the command prompt, you can use the F8 key as an up arrow. Press F8 to scroll through the command history. F8 does not stop when it reaches the top of the list but rotates to the bottom. F8 is also useful for finding previously executed commands. To find dir commands, type di at the command prompt and press F8. The prompt cycles through the command history and shows commands that start with di.

F9: Jump to command number. Scrolling through old commands is time consuming. You can use the F9 key to jump to a command. You must first use F7 to determine the command number. F9 is useful for repetitive work when you have to recall a command many times. F9 places the command at the prompt without executing the command, so you can modify it if necessary. You can use F9 while viewing the command history list. Suppose you see a command in the history list that is close to the command you want. Press F9 and enter that command number. This action places the command at the prompt, and you can then modify the command.

Make Yourself at Home
Customizing the command prompt saves you time in administering NT. In addition, if you miss the UNIX or OS/2 prompts, you can emulate many of their features.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.