JSI Tip 0294 - Using DOSKEY.

Jerold Schulman

October 30, 1997

5 Min Read
ITPro Today logo in a gray background | ITPro Today

The Doskey program is available in all character-based, interactive programs such as CMD.EXE and FTP.EXE. Doskey maintains a command history buffer and macros for each program started. The syntax is:

doskey [/reinstall] [/listsize=size] [/macros:[all | exename] [/history] [/insert|/overstrike] [/exename=exename] [/macrofile=filename] [macroname=[text]]

where:

 /reinstall  

Clears the command history buffer.  

 /listsize=size  

Specifies the maximum number of commands in the history buffer.  

 /macros  

Displays a list of all Doskey macros. You can use a redirection symbol (>) with the /macros switch to redirect the list to a file. You can abbreviate the /macros switch as /m.   

 all  

Displays Doskey macros for all executables.  

 exename  

Displays Doskey macros for the specified executable.  

 /history  

Displays all commands stored in memory. You can use a redirection symbol (>) with the /history switch to redirect the list to a file. You can abbreviate the /history switch as /h.   

 /insert | /overstrike  

Specifies whether new text you type is to replace old text. If you use the /insert switch, new text that you type on a line is inserted into old text (as if you had pressed the INSERT key). If you use the /overstrike switch, new text replaces old text. The default setting is /overstrike.  

 /exename=exename  

Specifies the program (executable) in which the Doskey macro will run.  

 /macrofile=filename  

Specifies a file containing macros to install.  

 macroname=[text]  

Creates a macro that carries out the commands specified by text. Macroname specifies the name you want to assign to the macro. Text specifies the commands you want to record. If text is left blank, macroname is cleared of any assigned commands.  

The /macros and /history switches are useful for saving macros and commands. To save all current doskey macros, type:

doskey /macros > cur

To then to use cur, type:

doskey /macrofile=cur

To save all the commands in the buffer to a batch file, type:

doskey /history > abatch.bat

To create a macro with multiple commands, use the $t syntax, variables are $1 to $9, and $* will append anything you type after the macro name:

doskey nd=md $1$Tcd $1

When you type nd Jerry, nd will create a folder Jerry and switch to it.

To delete the nd macro, type:

doskey nd=

To recall a command:

 UP ARROW  

Recalls the command you used before the one displayed.  

 DOWN ARROW  

Recalls the command you used after the one displayed.                           

 PAGE UP  

Recalls the oldest command you used in the current session.  

 PAGE DOWN  

Recalls the most recent command you used.   

You can edit a command line:

 LEFT ARROW  

Moves the cursor back one character.  

 RIGHT ARROW  

Moves the cursor forward one character.   

 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.   

 F1  

Copies one character from the same column in the template to the same column in the Windows NT command prompt. (The template is a memory buffer that holds the last command you typed.)   

 F2  

Searches forward in the template for the next key you type after pressing F2. Doskey inserts the text from the template up to but not including the character you specify.   

 F3  

Copies the remainder of the template to the command line. Doskey begins copying characters from the position in the template that corresponds to the position indicated by the cursor on the command line.   

 F4  

Deletes characters from the current cursor position up to a character you specify. To use this editing key, you press F4 and type a character. Doskey deletes the characters from the current cursor position to the first letter specified.   

 F5  

Copies the template into the current command line.   

 F6  

Places an end-of-file character (CTRL+Z) at the current cursor position.   

 F7  

Displays all commands for this program stored in memory in a pop-up box. Use the up and down arrow keys to select the command you want and press ENTER. The command will run. You can also note the sequential number in front of the command and use this number in conjunction with the F9 key.   

 ALT+F7  

Deletes all commands stored in memory for the current history buffer.   

 F8  

Displays all commands in the history buffer that start with the characters in the current command.

 F9  

Prompts you for a history buffer command number, then displays the command associated with the number you specify. Press ENTER to run the command. To display all the numbers and their associated commands, press F7.   

 ALT+F10  

Deletes all macro definitions.   

You can use the following special characters to control command operations when defining a macro:

 $G or $g  

Redirects output. Use either of these special characters to send output to a device or a file instead of to the screen. This character is equivalent to the redirection symbol for output (>).   

 $G$G or $g$g  

Appends output to the end of a file. Use either of these special double characters to append output to an existing file rather than replace the data in the file. These double characters are equivalent to the "append" redirection symbol for output (>>:).   

 $L or $l  

Redirects input. Use either of these special characters to read input from a device or a file instead of from the keyboard. This character is equivalent to the redirection symbol for input (<).   

 $B or $b  

Sends macro output to a command. Using one of these special characters is equivalent to using the pipe (|) on a command line.   

 $T or $t  

Separates commands. Use either of these special characters to separate commands when you are creating macros or typing commands on the Doskey command line. Using one of these special characters is equivalent to using the ampersand (&) on a command line.   

 $$  

Specifies the dollar-sign character ($).  

You cannot run a Doskey macro from a batch program.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like