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
-
Open Command Prompt:
Press
Win + R, typecmd, and hit Enter. Alternatively, search for "Command Prompt" in the Start menu. -
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.
-
Verify history settings:
Type
set HISTFILEand 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 indoskey /history.
Note: Windows 10/11 also support the
historycommand (similar to Linux). Typehistoryand 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.
- If it returns
-
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.
-
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).
-
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. -
Clear history (optional):
To reset the history, delete the
cmdhistory.txtfile 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 /historyfirst. -
Not saving history to a file: If you see commands in
doskey /historybut not incmdhistory.txt, the history isn’t being persisted between sessions. EnableHISTAPPENDto fix this. - Ignoring system updates: Windows updates sometimes reset CMD settings. After updating, recheck your history configuration (Step 3).
-
Confusing
doskeywithhistory: Older Windows versions rely ondoskey, while newer ones supporthistory. Test both commands if nothing appears.
Tips
-
Use shortcuts: Press
F7in Command Prompt to pull up a history list (if enabled). This is faster than typingdoskey /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
AutoRunregistry 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.txtfile to another location to preserve your command log. -
Use PowerShell instead: If CMD history is unreliable, PowerShell has built-in history with
Get-Historyand supports filtering better (e.g.,Get-History | Where-Object {$_.CommandLine -like "*ip*"}).
Troubleshooting
If your CMD history isn’t working, follow this order:
-
Check basic history:
Run
doskey /historyandhistory. If either shows nothing, proceed to the next step. -
Verify the history file exists:
Navigate to
%USERPROFILE%(pressWin + R, type%userprofile%, thenEnter) and look forcmdhistory.txt. If it’s missing, history isn’t being saved. -
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
-
Restart Command Prompt:
Close all CMD windows and reopen one. Type a test command (e.g.,
echo test) and check history again. -
Check for corrupted settings:
Run
reg delete "HKCU\Console" /v QuickEdit /f(then reboot) if you suspect a registry conflict from earlier edits. -
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.
- 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.
- 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.