DOSKEY.exe

Recall and edit commands at the DOS prompt, and create macros. You cannot run a Doskey macro from a batch file.

Syntax
      DOSKEY [options] [macroname=[text]]

Key
   macroname  : A short name for the macro.

        text  : The commands you want to recall.

      options : for working with macros...

   /MACROFILE=filename Specify a file of macros to install

   /MACROS             Display all Doskey macros

   /EXENAME=exename    Specify an  executable other than cmd.exe

   /MACROS:exename     Display all Doskey macros for the given executable

   /MACROS:ALL         Display all Doskey macros for all executables

   ALT+F10             Clear macro definitions

   options : for working with the Command Buffer...

   /HISTORY           : Display all commands stored in memory.
   /LISTSIZE=size     : Limit the number of commands remembered by the buffer.
   /REINSTALL         : Install a new copy of Doskey (clears the buffer).

   In normal use the command line is always in overwrite mode, DOSKEY can be used to
   change this to Insert, the insert key will always toggle from one to the other

   /INSERT           : By default new text you type at the command line
                       will be inserted in old text

   /OVERSTRIKE       : By default new text you type at the command line
                       will overwrite old

   /m /m: and /h are abbreviations for /macros /macros: and /history respectively.
   These provide compatibility with old MS-DOS versions of DOSKEY.

In addition to the above, DOSKEY is loaded into memory for every cmd session so you can use Keyboard shortcuts at the command line

The size of the command history can be set from Control Panel, Console or from the properties of any cmd shortcut. Clear all history with DOSKEY /REINSTALL

Examples

A macro to open notepad
DOSKEY note=notepad.exe

A macro to open WordPad
DOSKEY wpad="C:\Program Files\Windows NT\Accessories\wordpad.exe"

A macro called `d' to run dir/w
DOSKEY d=dir/w

A macro to disable the FORMAT command (n.b. Doskey is not really a reliable method for disabling commands, it is easily bypassed by running the full command path/ extension or creating a different macro.)
DOSKEY Format=Echo I've disabled the Format command.

More advanced macro definitions:

   $T     If you put more than one command in a DOSKEY macro, use $T. 
          to separate them. Equivalent to & in a batch file.

   $1-$9  Parameters, equivalent to %1-%9 in a batch file.

   $*     This represents ALL the parameters $1-9

A macro to open a file with WordPad:
DOSKEY wpad="C:\Program Files\Windows NT\Accessories\wordpad.exe" $1
Using the above macro:
>wpad MyTextfile.txt

Save and restore macro definitions

DOSKEY macros are only saved for the current session.
The command:
doskey /macros >macros.cmd
Will list all current macro definitions into macros.cmd, edit this file and place DOSKEY at the start of each line. Then to restore all the doskey macros setup in the current session at a later date, just run ' macros.cmd'.

“No man steps in the same river twice, for it's not the same river, and he's not the same man” ~ Heraclitus

Related:

Syntax - Batch file macros
Powershell: SendKeys (Snapin)
Equivalent bash commands (Linux): m4 - Macro processor, history - Command history


© Copyright SS64.com 1999-2014
Some rights reserved