DOSKEY - Macros and Aliases

Maintained on

Typing long commands such as cd /d C:\Users\user\Documents\Projects or dir /a /o:-d over and over is tedious.

The DOSKEY command lets you give frequently used commands a short name. This mechanism is called a macro (what other shells call an alias).

Basic Usage

DOSKEY macro_name=command

Example

Create a macro so that typing ls runs dir.

doskey ls=dir $*
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>doskey ls=dir $*

After registering it, typing ls shows the same result as dir.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>ls
Volume in drive C is Windows
Directory of C:\Users\user
(rest omitted)
C:\users\user>
おすすめ書籍※ 広告を含む場合があります
中小企業経営者のためのRPA入門 RPA導入を成功させる方法

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超入門

60分でわかる! AIエージェント 超入門

コマンドラインの黒い画面が怖いんです。

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

Macros work only at the start of a command

Only the first word of the line you type is expanded as a macro. Macros also work only when you type them interactively; they cannot be used inside batch files.

Macros That Accept Arguments

In a macro definition you can use special symbols to receive the arguments typed after the macro name.

SymbolDescription
$1–$9The 1st to 9th argument typed after the macro name
$*All arguments typed after the macro name
$TCommand separator (replaces &); chains multiple commands
$GReplaces the redirection symbol >
$LReplaces the redirection symbol <
$BReplaces the pipe |

If you write >, <, | or & directly in a macro definition, they are interpreted first as redirection, pipes or command separators for the DOSKEY command itself. Use the symbols in the table instead.

Pass All Arguments ($*)

doskey ll=dir /a /o:-d $*

Typing ll C:\Windows runs dir /a /o:-d C:\Windows. For the options of dir, see

.

Use Individual Arguments ($1)

doskey cdd=cd /d $1

Typing cdd D:\Work moves you to D:\Work, even on a different drive.

Chain Multiple Commands ($T)

doskey mkcd=mkdir $1 $T cd $1

Typing mkcd test creates the folder test and then moves into it. Commands chained with $T run one after another even if the previous command fails.

チェック

To run the next command only if the previous one succeeds (&&), write $T$T. For more on creating folders, see

.

List Macros

You can view registered macros with /macros (short form: /m).

doskey /macros
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>doskey /macros
ls=dir $*
ll=dir /a /o:-d $*
cdd=cd /d $1
mkcd=mkdir $1 $T cd $1
C:\users\user>

Delete a Macro

To delete a macro, define it with nothing on the right side of =.

doskey ls=

Macros Disappear When You Close the Window

Macros registered with DOSKEY are valid only within that Command Prompt window. They disappear when you close it, so you would have to register them again each time.

To avoid this, save the macro definitions to a file and load it at startup.

Save Macros to a File

You can write the current macros to a file as the output of /macros. For redirection, see

.

doskey /macros > %USERPROFILE%\macros.doskey

The file is a plain text file with one macro per line in the form name=command. You can edit it directly in Notepad or any text editor.

ls=dir $*
ll=dir /a /o:-d $*
cdd=cd /d $1
mkcd=mkdir $1 $T cd $1
チェック

The output of /macros is written in the console code page (for example, Shift_JIS-based code page 932 on Japanese Windows). If you edit and re-save the file, use ANSI or UTF-8 without a BOM. For more on character encoding, see

.

Load Macros from a File

Specify the file with the /macrofile option to register them all at once.

doskey /macrofile=%USERPROFILE%\macros.doskey

Load Automatically at Startup

To load them every time you open Command Prompt, the easiest way is to change the target of a shortcut as follows.

%windir%\system32\cmd.exe /k doskey /macrofile=C:\Users\user\macros.doskey

Replace user with your own user name. The /k option keeps the window open after running the specified command.

Be careful with the registry AutoRun value

If you set a command in the AutoRun value under HKCU\Software\Microsoft\Command Processor in the registry, it runs every time any Command Prompt starts. However, it also affects cmd instances launched from batch files and other programs, which can cause unexpected behavior. If you set it, note the previous value so you can restore it. We recommend starting with the shortcut method above.

Managing Command History

DOSKEY also manages the command history. The /history option is introduced in

.

OptionDescription
/historyDisplays the stored command history
/listsize=nSets the number of commands to keep in history to n
/macrosLists macros
/macros:allLists macros for all running executables (including non-cmd ones)
/macrofile=fileLoads macros from a file
/reinstallStarts a new instance of DOSKEY and clears the history buffer
doskey /listsize=100

Practical Example: Register Commonly Used Operations

Here is an example macro file for everyday development work.

ls=dir $*
ll=dir /a /o:-d $*
cdd=cd /d $1
mkcd=mkdir $1 $T cd $1
which=where $*
ip=ipconfig $*

which is a short way to call

, and ip is a short way to call .

Not available in PowerShell

DOSKEY macros are a feature of Command Prompt (cmd.exe). PowerShell uses different mechanisms, such as Set-Alias and functions.

Summary

OperationCommand
Register a macrodoskey name=command
Pass all arguments$*
Chain multiple commands$T
List macrosdoskey /macros
Delete a macrodoskey name=
Save to a filedoskey /macros > file
Load from a filedoskey /macrofile=file

Practice Questions

Practice Problem

Which is the correct way to list the macros registered with DOSKEY?

回答がサーバーに送信されることはありません
Practice Problem

What does $* mean in a DOSKEY macro definition?

回答がサーバーに送信されることはありません
#Command Prompt #DOSKEY #Macro #Alias #Command