CMD Simulator
System Informationdoskey

DOSKEY Command Guide - Command History and Macros in Windows CMD

Learn how to use the DOSKEY command for command recall, history, and macro creation in Windows Command Prompt. Includes syntax, /history, /macros, and productivity examples.

Rojan Acharya··Updated Mar 23, 2026
Share

The doskey command is a Windows Command Prompt utility that provides command-line recall, editing, and macro creation. Use arrow keys to recall previous commands (when doskey is loaded), doskey /history to display command history, and doskey macro=command to create keyboard shortcuts—enhancing productivity for power users, system administrators, and developers who work extensively in CMD.

Whether you're recalling long commands without retyping, creating aliases for complex operations, building a personalized command vocabulary, or streamlining repetitive administrative tasks, mastering doskey transforms the Command Prompt into a more efficient environment. IT professionals rely on doskey for faster troubleshooting, script development, and day-to-day system administration.

This comprehensive guide covers doskey syntax, command history, macro creation, practical examples, troubleshooting tips, related commands, and frequently asked questions. By the end, you'll confidently use doskey to boost your CMD productivity.

What Is the Doskey Command?

The doskey command is a command-line enhancement utility that has been part of Windows since MS-DOS. It provides:

  • Command history – Recall previous commands with Up/Down arrows (when doskey is loaded)
  • Command editing – Left/Right arrows, Home, End, Insert, Delete for line editing
  • Macros – Create aliases that expand to full commands (e.g., lldir)
  • Persistent history – History is session-based; macros persist only in current session unless saved

By default, CMD in recent Windows versions loads doskey automatically for history and editing. The doskey command lets you manage macros and inspect history explicitly. Available in Command Prompt (cmd.exe); PowerShell uses different mechanisms for history.

Doskey Command Syntax

DOSKEY [/reinstall] [/listsize=size] [/history] [/macros] [macroname=[text]]

Parameters and Switches

ParameterDescription
macroname=[text]Define a macro. macroname=command. Use $* for arguments.
/reinstallReinstalls Doskey, clearing macros. Fresh start.
/listsize=sizeSet history buffer size (default often 50). Number of commands to remember.
/historyDisplays command history. Same as F7 in some CMD configurations.
/macrosDisplays all defined macros.

Macro Syntax

  • doskey name=command – Creates macro: typing name runs command
  • $* – Placeholder for all arguments: doskey f=findstr $*f hello file.txt runs findstr hello file.txt
  • $1$9 – Positional parameters
  • $T – Separator for multiple commands: doskey m=dir $T more
  • $G – Redirect output: doskey l=dir $G list.txt
  • $L – Pipe: doskey p=dir $L findstr "txt"
  • $B – Pipe to command: same as $L
  • $$ – Literal $ character

Parameters in Detail

Command History (/history)

Displays the list of commands entered in the current session. Commands are recalled with Up/Down arrows. History is lost when CMD closes unless using persistence tools.

Macros (/macros)

Lists all macros defined in the current session. Macros are temporary; they do not persist across CMD sessions unless loaded via startup script or registry.

Macro Definition

Define with doskey macroname=command. Use $* to pass all following arguments to the command. Useful for shortening long commands or creating memorable aliases.

Examples

Display Command History

View all commands entered in the current session:

doskey /history

Output lists commands in order. Use when you need to find a previous command to copy or modify.

Create Simple Alias

Create a macro that runs dir when you type ll:

doskey ll=dir

Type ll and press Enter—dir runs. Useful for Unix/Linux users accustomed to ls or ll.

Macro with Arguments

Pass arguments to the macro command:

doskey f=findstr $*

Typing f "error" log.txt runs findstr "error" log.txt. The $* replaces with all arguments.

Multiple Commands in Macro

Chain commands with $T:

doskey df=dir /b $T findstr /v "."

Runs dir /b, then pipes to findstr. $T is command separator.

Macro with Redirection

doskey sd=systeminfo $G sysinfo.txt

Typing sd runs systeminfo > sysinfo.txt. $G is redirect output.

List All Macros

See currently defined macros:

doskey /macros

Output format: macro=command. Use to verify definitions or document your setup.

Clear Macros and Reinstall

Reset doskey to default state:

doskey /reinstall

Removes all macros. Use when cleaning up or troubleshooting macro conflicts.

Increase History Size

Remember more commands:

doskey /listsize=100

Increases buffer to 100 commands. Default varies by Windows version.

Common Productivity Macros

doskey h=doskey /history
doskey m=doskey /macros
doskey ..=cd ..
doskey ip=ipconfig $*

Short aliases for frequently used commands.

Common Use Cases

  1. Recall long commands – Use Up arrow to bring back complex commands (ipconfig /all, robocopy with many switches) without retyping. Essential for troubleshooting repetition.

  2. Create Unix-style aliases – Map ll to dir, clear to cls, grep to findstr for users familiar with Unix/Linux.

  3. Shorten frequent commands – Create g=gpresult or s=systeminfo to save keystrokes during administration.

  4. Add default argumentsdoskey ip=ipconfig /all so ip always runs ipconfig with full output.

  5. Chain common operations – Macro that runs dir then pauses: doskey dp=dir $T pause.

  6. Parameterized macros – Use $* for flexible macros: doskey p=ping $* so p google.com works.

  7. Quick navigationdoskey ..=cd .. for fast parent directory change.

  8. Script development – Test command combinations via macros before writing batch files.

  9. Training and demos – Define macros at start of demo so short commands produce expected output.

  10. Reduce typos – Alias for commands you frequently mistype.

  11. Standardize across team – Share a set of macros in a login script for consistent workflows.

  12. Audit your usage – Use /history to see what commands you run most; create macros for them.

Tips and Best Practices

  1. Macros are session-only – Macros disappear when CMD closes. Use a startup script or AutoRun registry key to load macros automatically.

  2. Save macro definitions – Create a .bat file that runs your doskey commands; run it at CMD start or add to Autorun: reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "path\to\macros.bat".

  3. Avoid overwriting commands – Don't create doskey dir=... unless you intend to replace dir. Use unique macro names.

  4. Use $ for flexibility* – Macros with $* accept arguments: doskey f=findstr $* works with any findstr usage.

  5. Test macros before reliance – Verify macro expansion works before using in critical workflows.

  6. Quote paths in macros – If macro includes paths with spaces, use quotes: doskey go=cd "C:\Program Files\App".

  7. Combine with Tab completion – Tab completion works with macro names. Type part of macro and Tab to complete.

  8. Document your macros – Keep a list of macros and their purposes. Use doskey /macros to export current set.

  9. Use /reinstall to debug – If macros behave unexpectedly, doskey /reinstall clears all and gives clean slate.

  10. $T for multiple commands – Separate commands in a macro with $T. Each runs in sequence.

  11. Check history size – If history seems truncated, increase with /listsize=. Default may be 50.

  12. PowerShell alternative – For persistent aliases and functions, consider PowerShell's Set-Alias and function definitions in profile.

Troubleshooting Common Issues

Macros Disappear After Closing CMD

Problem: Macros work during session but are gone when CMD is reopened.

Cause: Macros are stored only in memory. They do not persist by default.

Solution: Create a batch file (e.g., macros.bat) with your doskey commands. Run it when starting CMD, or set Autorun in registry to run it automatically: HKCU\Software\Microsoft\Command Processor → AutoRun.

Prevention: Use Autorun or a shortcut that runs cmd /k macros.bat to load macros on every CMD start.

Arrow Keys Don't Recall Commands

Problem: Up/Down arrows don't show previous commands.

Cause: Doskey may not be loaded (rare in modern CMD), or you're in a different environment (e.g., PowerShell, some terminals).

Solution: Run doskey to ensure it's loaded. In CMD, doskey is usually auto-loaded. In PowerShell, history uses different keys (Up/Down work for history there too, but mechanism differs). Verify you're in cmd.exe.

Prevention: Use standard cmd.exe. Some alternate terminals or environments may not support doskey.

Macro Doesn't Accept Arguments

Problem: Macro runs but arguments are ignored.

Cause: Macro definition doesn't include $* or $1–$9 for arguments.

Solution: Redefine with $*: doskey f=findstr $*. Now f "text" file.txt passes arguments to findstr.

Prevention: Use $* when the macro should forward arguments to the command.

"Unknown switch" or Syntax Error

Problem: Doskey reports error when defining macro.

Cause: Special characters (= $ etc.) may need escaping or different handling. Conflicting switches.

Solution: For equals in command, try doskey m=echo $G file (for redirect). Some characters are tricky. Simplify macro and add complexity gradually.

Prevention: Test simple macros first. Check doskey documentation for $ character usage.

Macro Name Conflicts with Command

Problem: Typing macro name runs a different command or nothing.

Cause: Macro name matches or conflicts with built-in command, batch file, or another macro.

Solution: Use unique macro names. Avoid names like dir, copy, cd. Use doskey /reinstall to clear and redefine.

Prevention: Use distinctive names: ll for dir, gg for grep-alias, etc.

History Too Short

Problem: History doesn't retain enough commands.

Cause: Default listsize may be 50 or less.

Solution: Run doskey /listsize=200 (or desired number). Takes effect immediately.

Prevention: Add to startup script so it runs each session.

Related Commands

cmd – Command Interpreter

cmd starts a new Command Prompt. Use cmd /k script.bat to start CMD and run a script (e.g., loading doskey macros), keeping the window open.

When to use: Start CMD with macros pre-loaded via /k and a batch file that runs doskey commands.

set – Environment Variables

set creates environment variables. You can use variables in doskey macros via $env:name (PowerShell) or %VAR% in batch. For CMD macros, use literal values or $* for arguments.

When to use: Store paths or options in variables; reference in batch files that call doskey.

prompt – Customize Prompt

prompt changes the CMD prompt. Combine with doskey for a productive session: custom prompt plus macros and history.

When to use: Personalize CMD appearance. Independent of doskey but often used together.

PowerShell – Alternative Environment

PowerShell has built-in history (Up/Down) and supports Set-Alias and functions in $PROFILE for persistent customization. More powerful than doskey for complex aliases.

When to use: If you need persistent, programmable aliases and richer scripting, use PowerShell. Doskey suits CMD-focused workflows.

Frequently Asked Questions

What does the doskey command do?

Doskey provides command history (recall with Up/Down), command-line editing, and macro creation. Macros let you define short names that expand to full commands.

How do I recall previous commands?

Press Up Arrow to recall older commands, Down Arrow for newer. Works when doskey is loaded (default in CMD). Use doskey /history to list all.

How do I create a command alias?

Use doskey aliasname=command. Example: doskey ll=dir. Typing ll then runs dir. Use $* to pass arguments: doskey f=findstr $*.

Do doskey macros persist after closing CMD?

No. Macros are session-only. To persist, run doskey commands from a script at CMD start, or use registry Autorun to run a batch file that defines macros.

Can I use doskey in PowerShell?

Doskey is a CMD utility. PowerShell has its own history (Up/Down) and uses Set-Alias and functions for persistent aliases. Use PowerShell's mechanisms in PowerShell.

How do I pass arguments to a doskey macro?

Use $* in the macro definition: doskey p=ping $*. Then p google.com runs ping google.com. Use $1, $2, etc. for specific positional args.

How do I list all my macros?

Run doskey /macros. Output shows each macro and its definition.

How do I clear all macros?

Run doskey /reinstall. This clears all macros and reinitializes doskey.

What is the maximum history size?

Controlled by /listsize. Default varies (often 50). Set doskey /listsize=999 for large history. Very large values may use more memory.

Why don't my arrow keys work for history?

Ensure you're in cmd.exe (not PowerShell, or a different shell). Run doskey to load. Some GUI terminal emulators may not support doskey's line editing.

Quick Reference Card

CommandPurposeExample
doskey /historyList command historyView previous commands
doskey /macrosList all macrosSee definitions
doskey name=cmdCreate macrodoskey ll=dir
doskey name=cmd $*Macro with argsdoskey f=findstr $*
doskey /reinstallClear macrosReset to default
doskey /listsize=nHistory bufferdoskey /listsize=100

Summary

The doskey command enhances CMD with command history, line editing, and macros. Use Up/Down arrows to recall commands, doskey macro=command to create aliases, and $* to pass arguments. Macros are session-only; use a startup script or Autorun for persistence. Combine with prompt and other CMD features for an efficient command-line workflow. Master doskey for faster system administration and development.

Practice the doskey command in our Windows Command Simulator. Browse the Commands Reference for all Windows CMD utilities. Explore prompt for prompt customization and set for environment variables.