The Command Prompt (CMD) in Windows keeps a history of your typed commands, but it’s not always obvious how to access it. If you want to view past commands or reuse them, you don’t need third-party tools—Windows has built-in ways to retrieve your history. The doskey /history command shows all past inputs (if enabled), while history in newer Windows versions (10/11) also works. However, some users see no history at all, which usually means the feature is disabled or a setting was overlooked.

What You'll Need

  • A Windows PC running Windows 7 or later (history works differently in older versions).
  • Administrator privileges (only needed if modifying history settings like auto-save).
  • The Command Prompt (CMD) app (accessible via Start menu or Win + R + typing "cmd").

Step-by-Step

  1. Open Command Prompt: Press Win + R, type cmd, and hit Enter. Alternatively, search for "Command Prompt" in the Start menu.
  2. Check if command history is enabled: Type the following command and press Enter:
    doskey /history

    This will display a list of recently used commands (if history logging is on). If nothing appears, proceed to Step 3.

  3. Verify history settings: Type set HISTFILE and press Enter.
    • If it returns HISTFILE= or nothing, history is not saved to a file.
    • If it returns a path (e.g., C:\Users\YourName\ntuser.dat), history is stored but may not always display in doskey /history.

    Note: Windows 10/11 also support the history command (similar to Linux). Type history and press Enter to see past commands. If this doesn’t work, enable it via:

    reg add "HKCU\Console" /v QuickEdit /t REG_DWORD /d 0 /f

    Warning: This registry edit is safe but requires a reboot to take effect.

  4. Enable or modify history logging:

    To ensure history is saved, run these commands in sequence:

    doskey /macrofile=~\%USERPROFILE%\doskey.mac
    set PROMPT=$P$G
    set HISTFILE=%USERPROFILE%\cmdhistory.txt
    set HISTSIZE=1000
    set HISTAPPEND=1

    These commands:

    • Save macros to a file in your user profile.
    • Set the history file to cmdhistory.txt (created automatically).
    • Increase the number of stored commands to 1,000.
    • Append new history entries to the file instead of overwriting.
  5. View saved history manually:

    Close and reopen Command Prompt. Then, type:

    type %USERPROFILE%\cmdhistory.txt

    This will display all saved commands. If the file is empty, history logging isn’t working (check Step 3).

  6. Reuse a past command:

    In Command Prompt, press the Up Arrow key to navigate through your history. Alternatively, type !line_number (e.g., !5) to repeat the 5th command from the top.

  7. Clear history (optional):

    To reset the history, delete the cmdhistory.txt file or run:

    del %USERPROFILE%\cmdhistory.txt

Common Mistakes

  • Assuming history always works: Many users don’t realize history is disabled by default unless explicitly configured (like in Step 3). Always check doskey /history first.
  • Not saving history to a file: If you see commands in doskey /history but not in cmdhistory.txt, the history isn’t being persisted between sessions. Enable HISTAPPEND to fix this.
  • Ignoring system updates: Windows updates sometimes reset CMD settings. After updating, recheck your history configuration (Step 3).
  • Confusing doskey with history: Older Windows versions rely on doskey, while newer ones support history. Test both commands if nothing appears.

Tips

  • Use shortcuts: Press F7 in Command Prompt to pull up a history list (if enabled). This is faster than typing doskey /history.
  • Search history: Type doskey /history | find "searchterm" to filter commands by keyword (e.g., find "ipconfig").
  • Permanent fixes: To make history settings stick across reboots, add the commands from Step 3 to your AutoRun registry key or use a script in Startup:
    reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "doskey /macrofile=~\%USERPROFILE%\doskey.mac" /f
  • Export history for backup: Copy the cmdhistory.txt file to another location to preserve your command log.
  • Use PowerShell instead: If CMD history is unreliable, PowerShell has built-in history with Get-History and supports filtering better (e.g., Get-History | Where-Object {$_.CommandLine -like "*ip*"}).

Troubleshooting

If your CMD history isn’t working, follow this order:

  1. Check basic history: Run doskey /history and history. If either shows nothing, proceed to the next step.
  2. Verify the history file exists: Navigate to %USERPROFILE% (press Win + R, type %userprofile%, then Enter) and look for cmdhistory.txt. If it’s missing, history isn’t being saved.
  3. Re-enable history logging: Run these commands in CMD:
    set HISTFILE=%USERPROFILE%\cmdhistory.txt
    set HISTSIZE=1000
    set HISTAPPEND=1
    doskey /macrofile=~\%USERPROFILE%\doskey.mac
  4. Restart Command Prompt: Close all CMD windows and reopen one. Type a test command (e.g., echo test) and check history again.
  5. Check for corrupted settings: Run reg delete "HKCU\Console" /v QuickEdit /f (then reboot) if you suspect a registry conflict from earlier edits.
  6. Reset CMD profile (last resort):

    If nothing works, reset the Command Prompt profile to default:

    reg delete "HKCU\Console" /f

    Warning: This removes all custom CMD settings, including color schemes and macros. Reopen CMD to restore defaults.

  7. Try a different user account: If history works in another account, the issue is likely account-specific (e.g., corrupted user profile). Test this by logging in as a guest or creating a new user.
  8. Check for malware: If history was working but suddenly stopped, run a full antivirus scan. Some malware can intercept or delete CMD input/output.

Frequently Asked Questions

Why does my CMD history show nothing?

History is disabled by default unless you’ve enabled HISTFILE and HISTSIZE. Run set HISTFILE to check if it’s set, or configure it manually (see Step 3).

Can I see deleted history?

No. Once you delete cmdhistory.txt or clear the history buffer, the commands are gone permanently. However, you can recover them temporarily by checking the Windows Event Log (search for "Event Viewer" and look under Windows Logs > Application for CMD-related entries).

Does CMD history work in PowerShell?

No. PowerShell has its own history system (accessed with Get-History), which is separate from CMD’s doskey history. To reuse CMD commands in PowerShell, copy them manually.

How do I save CMD history to a specific file?

Edit the HISTFILE variable to point to your desired path, e.g., set HISTFILE=C:\Backup\cmd_backup.txt. Then ensure HISTAPPEND=1 is set to avoid overwriting.

Why does my history include commands from other users?

CMD history is user-specific—each account stores its own commands in %USERPROFILE%\cmdhistory.txt. If you see mixed commands, you’ve either logged into the wrong profile or a shared script is modifying the file. Check file permissions in %USERPROFILE%.

Can I use CMD history remotely?

No. CMD history only works locally on the machine where you run Command Prompt. To access past commands on a remote server, you’d need to SSH or RDP into the server first, then check its local history.