Undocumented Command Prompt Tips
You can customize the command prompt and use several function keys to make administering NT easier.
July 31, 1998
Learn NT command prompt features that resemble those of UNIX and OS/2
The Windows NT command prompt has many useful function keys andother features. Administrators who migrate to NT from UNIX or OS/2 will likethese features because they emulate UNIX and OS/2's command prompts, and theystreamline daily tasks. Many of the features I discuss are not documentedelsewhere.
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 suchas the Command History, QuickEdit Mode, and Insert Mode; and layout and bufferoptions.
Colors and titles. Users commonly change the prompt window'sdefault color. Start a command prompt, select the Control menu (click the MS-DOSicon in the top left corner, as Screen 1, page 168, shows), and selectProperties. 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 askswhether you want to apply the changes only to the current window or to theshortcut that started the window. If you want to apply your custom settings asthe default when you start a command prompt, modify the shortcut.
You can also change the default colors directly from a command prompt. Goto a command prompt and type
color
The attr option is the foreground and background color attributes, writtenas two hex digits. The first hex digit specifies the background color, and thesecond digit specifies the text color. For a list of color attributes, go to acommand prompt and type
color /?
To revert to the default colors, execute the color command without enteringoptions.
You can use the title command to change the title of a command promptwindow. The command prompt window's default title is the same as the label ofthe icon you used to start the prompt (i.e., Command Prompt). Sometimes you havemultiple command prompts open. You launch multiple command prompts with oneicon, so the command prompt windows have identical titles. Changing the titleslets you differentiate among the prompts. To change the title permanently, editthe icon's label. Right-click the icon, select Rename, and enter the title youwant. For short-term changes, use the title command. Go to a command prompt andtype
title
General options. Screen 2 shows the settings on the Optionstab of the Command Prompt Properties dialog box. The following items are themost useful: Command History, QuickEdit Mode, and Insert Mode.
In the Command History section, set the Buffer Size to the number of oldcommands that you want in the history. You can use the up and down arrows andthe F7, F8, and F9 keys to recall commands in the history buffer. You must closeand reopen the command prompt for a change in the buffer size to take effect. Toeliminate duplicates, select the Discard Old Duplicates option. The commandhistory is valid only while the command prompt is open. If you close the commandprompt, the command history disappears.
The QuickEdit Mode lets you copy and paste text from the command promptwithout using the control menu. Dragging your mouse over the text you want tocopy highlights a rectangular shape. In most Windows applications, when youhighlight part of a line and pull the mouse down, the highlighting automaticallystretches to the end of the line. In the QuickEdit Mode, the highlightingextends only to the corners of the drag rectangle. You can then copy the text toother 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 textthat is already there, select the Insert Mode option. To temporarily use theovertype mode from the command prompt, press the Insert key once. Press Insertagain to revert to insert mode. This feature works regardless of your defaultsetting.
Layout and buffers. Users often overlook NT's screen buffer,because it is not readily apparent. To set screen buffers, go to the CommandPrompt Properties dialog box and select the Layout tab. By default, the screenbuffer height and window height are 25, so you cannot scroll. To enable a longerbuffer, set the screen buffer height to a larger number, as Screen 3 shows. Youcan 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. Manyfunction keys perform the same action in NT as they did in DOS. Table 1, page170, lists the function and related keys available at the NT command prompt, aswell 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 repeatingparts of lengthy or complex command lines. You can use F2 to copy the currentcommand in the history buffer to the command prompt, up to the first occurrenceof the character you specify. Press F7 to see the current command. You can usethe up and down arrow keys to change the current command.
Suppose the current command in the history buffer is cd "programfilesplus!", and you want to move one directory level up to the NTdirectory. Directories with spaces in their names are cumbersome to type becausethey require quotation marks. To save time, perform the following steps. PressF2 and enter
p
to copy the line up to but not including the first p. The command line thencontains cd ". Press F2 again and enter
p
to copy the line to the next occurrence of p. The command line then containscd "program files. To complete the command, type
Windows NT"
F4: Character to delete up to. The F4 key is a quick way todelete characters to the right of the cursor. Suppose you enter a lengthy pathto change your directory to. As you execute the CD command, you realize that youhaven'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 WINNTSYSTEM32
INFTEMP. To bring back the command, press the up arrow. Press the Home key tomove the cursor to the beginning of the line. Press F4 and then press thespacebar to delete the command, up to but not including the space. The commandis then C:> WINNTSYSTEM32INFTEMP. Make sure you are in insert mode, enter
MD
and execute the command (i.e., C:>MD WINNTSYSTEM32INFTEMP).
In this simplified example, you can just as easily use the delete orbackspace key to remove the CD command. However, F4 saves time when you need todelete 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 theentire 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 youcan use Page Up and Page Down to scroll faster. You can press Esc to cancel thelist without taking action.
Press Enter to execute a highlighted command. The command you execute thenbecomes the current command in the history buffer. Thus, subsequent actions thatrelate to the history start from this command.
F8: Show previous command with search capability. If youhave nothing at the command prompt, you can use the F8 key as an up arrow. PressF8 to scroll through the command history. F8 does not stop when it reaches thetop of the list but rotates to the bottom. F8 is also useful for findingpreviously executed commands. To find dir commands, type di at the commandprompt and press F8. The prompt cycles through the command history and showscommands that start with di.
F9: Jump to command number. Scrolling through old commandsis time consuming. You can use the F9 key to jump to a command. You must firstuse F7 to determine the command number. F9 is useful for repetitive work whenyou have to recall a command many times. F9 places the command at the promptwithout executing the command, so you can modify it if necessary. You can use F9while viewing the command history list. Suppose you see a command in the historylist that is close to the command you want. Press F9 and enter that commandnumber. This action places the command at the prompt, and you can then modifythe command.
Make Yourself at Home
Customizing the command prompt saves you time in administering NT. Inaddition, if you miss the UNIX or OS/2 prompts, you can emulate many of theirfeatures.
About the Author
You May Also Like