3. Using the Built-in doskey Program
doskey is built in to the command prompt and keeps a
history of all the commands you enter in the current command prompt
session. You can easily retrieve previous commands so that you don’t
have to type them again. For example, suppose you’re trying to export a
DNS zone with the dnscmd /zoneexport pearson.pub pearson.txt command. However, instead, you enter the following command with only one “e” in zoneexport instead of two:
dnscmd /zonexport pearson.pub pearson.txt
dnscmd gives an
error and then displays help. You don’t have to retype the entire
command. Instead, you can just press the up arrow to retrieve the
command, press the left arrow until the cursor is positioned after zone,
add the second e, and then press Enter. The same command executes again without retyping it from scratch.
Tip
After making an edit, you don’t have to reposition the cursor at the end of the line. Simply press Enter to continue.
The following table shows the keys you can use to retrieve commands.
Keyboard Key | Description |
---|
Up arrow | Recalls the previous command. |
Down arrow | Recalls the next command in the doskey buffer. |
Page up | Recalls the oldest command in the current session. |
Page down | Recalls the most recent command in the current session. |
You can use the following keys when editing a retrieved doskey command.
Keyboard Key or Key Combination | Description |
---|
Left arrow | Moves the cursor back one character at a time. |
Right arrow | Moves the cursor forward one character at a time. |
CTRL + left arrow | Moves the cursor back one word. |
CTRL + right arrow | Moves the cursor forward one word. |
Home | Moves the cursor to the beginning of the line. |
End | Moves the cursor to the end of the line. |
Esc | Clears the command from the display. |
Note
The doskey buffer holds the last 50 commands by default; however, you can change that with the /listsize switch. For example, to extend the history buffer to 75, use the following command:
Tip
You can also change the buffer size by right-clicking the title bar, selecting Properties, and changing the buffer size. The buffer size value is the same as the listsize value.
The following are some of the useful commands you can use with doskey.
doskey Command | Description |
---|
c:\>doskey /history | Lists all commands in the history buffer. |
F7 | Displays the command history in a selectable popup dialog box. |
c:\>doskey /reinstall | Installs a new copy of doskey.exe and clears the command history buffer. |
doskey /listsize = number
c:\>doskey /listsize = 999
| Changes the size of the doskey buffer to the provided number. The example sets the buffer size to 999. |
4. Creating Mini Macros with doskey
You can create mini macros to make them available to
you in a command prompt session. For example, imagine that you expect to
enter sc stop netlogon and sc start netlogon many times. You can create two macros with the following commands:
doskey stpnl = sc stop netlogon
doskey sttnl = sc start netlogon
Now, you can simply enter stpnl at the command prompt to stop the netlogon service, and enter sttnl to start it.
Note
Macros are available only in the current session. If you close the command prompt and reopen it, the macro is lost.
doskey Command | Description |
---|
doskey macroKey = command
c:\>doskey stpnl = sc stop netlogon
c:\>doskey sttnl = sc start netlogon
| Creates
a macro that executes the command when the macro key is entered. The
examples create two macros named stop and start that can be used to stop
and start the netlogon service. |
| Executing the macro is the same as executing the command. These examples show how to execute the macros. |
c:\>doskey /macros | Displays all doskey macros in the session. |
5. Cutting and Pasting to and from the Command Prompt
You can cut text from, and paste text to, the command prompt. The process is a little different depending on how the Quick Edit Mode option is configured. Figure 4 shows the Options
tab of the Properties dialog box. You can access this by right-clicking
the title bar of the command prompt window and selecting Properties.
The QuickEdit Mode option changes the way you can cut and paste from the command line. The Insert Mode
option works just like the Insert key of the keyboard. It enables you
to insert characters in the line when enabled or overwrite characters in
the line when disabled.
Tip
If you want your changes to apply anytime the command
prompt window is open instead of only the current session, right-click
the title bar, select Defaults, and then select the options.
Copying from the Command Prompt Window
You can copy data from the command line to the Clipboard.
Quick Edit Mode Option | Result |
---|
If Quick Edit Mode is enabled (checked) | Use the mouse to highlight text and press the Enter key to copy highlighted text. |
If Quick Edit Mode is not enabled (unchecked) | Right-click in the command prompt window and select Mark. |
| Use the mouse to highlight text and press the Enter key to copy highlighted text. |
Note
Both of these methods copy the data to the Clipboard. You can then paste it into any other application (such as Notepad).
Pasting Data to the Command Prompt Window
You can paste any data that is in the Clipboard to the command line.
Quick Edit Mode Option | Result |
---|
If Quick Edit Mode is enabled (checked) | Right-click in the command prompt window and the data is pasted. |
If Quick Edit Mode is not enabled (unchecked) | Right-click in the command prompt window and select Paste. |
Note
If you copy a carriage return with the
command, the carriage return is pasted into the command prompt window.
In other words, when you paste it, it executes.