If you regularly use the Command Prompt (CMD) in Windows 11, you’ve probably entered dozens of commands during troubleshooting or automation tasks. But what if you need to look back at a previous command you ran?
Windows Command Prompt doesn’t display your command history by default once you close it — but while it’s open, there are several ways to view, scroll through, and even export your command history.
In this guide, we’ll show you multiple methods to view your Command Prompt history on Windows 11, including quick shortcuts, built-in commands, and history export options.
1. Use the Arrow Keys to Browse Command History
The quickest and most common way to view previous commands is by using the arrow keys directly in the Command Prompt window.
- Open Command Prompt by pressing Windows + R, typing
cmd, and pressing Enter. - Press the Up Arrow (↑) key to scroll backward through previous commands.
- Press the Down Arrow (↓) key to move forward again.
Each press shows the command you previously entered. Once you find the one you need, press Enter to execute it again.
This only works for commands run in the current session. Once you close the window, the history is cleared.
2. View the Full Command History with a Command
You can also display your entire command history within the current Command Prompt session using the doskey command.
- Open Command Prompt.
- Type the following and press Enter:
doskey /history - This will list all the commands you’ve executed since opening that Command Prompt window.
You can scroll up and copy any previous command directly from the output.
3. Save Command Prompt History to a Text File
If you want to keep a record of your commands — for documentation, debugging, or future reference — you can export your history to a text file.
- Open Command Prompt.
- Run the following command:
doskey /history > "%userprofile%\Desktop\cmd_history.txt" - Press Enter.
This will create a text file named cmd_history.txt on your Desktop containing all commands from your current session.
To view it, simply open the file in Notepad or any text editor.
Note: This only saves the history from the active Command Prompt session — you must export it before closing the window.
4. Use the F7 Key for a Pop-up Command History Menu
Windows CMD has a lesser-known built-in shortcut that opens a graphical menu of your previous commands.
- Open Command Prompt.
- Press the F7 key on your keyboard.
You’ll see a pop-up box displaying your recent command history. Use the arrow keys to scroll through the list and press Enter to re-run any command.
This feature is extremely useful when you don’t want to retype complex commands manually.
5. Use the F8 Key for Quick Command Search
The F8 key allows you to search through your command history quickly.
- Open Command Prompt.
- Start typing the beginning of a command you’ve used before.
- Press F8, and Command Prompt will auto-complete it with the most recent matching command from your history.
- Keep pressing F8 to cycle through other matches.
This feature works like a mini search function, perfect for recalling long or similar commands.
6. Enable Persistent Command History (Optional)
By default, Command Prompt doesn’t save your history after you close it. However, you can use Windows Terminal or PowerShell to preserve your history between sessions.
Using Windows Terminal:
If you run CMD inside Windows Terminal (the default terminal app in Windows 11), your command history is saved automatically.
- Open Windows Terminal (press Windows + X → Terminal).
- Select Command Prompt from the dropdown arrow in the title bar.
- Run some commands, then close and reopen Terminal.
- Press Up Arrow (↑) — your previous commands should reappear.
This feature works because Windows Terminal maintains a persistent history cache for each shell.
7. View Command History from PowerShell (Alternate Method)
If you often switch between Command Prompt and PowerShell, you can use PowerShell’s built-in command history system for reference.
- Open PowerShell (press Windows + X → Windows PowerShell).
- Type:
Get-History - You’ll see a list of all commands run in the current PowerShell session.
To export it, use:
Get-History | Out-File "$env:USERPROFILE\Desktop\powershell_history.txt"
This won’t show CMD commands but can help if you’re troubleshooting across multiple terminals.
8. Create a Script to Automatically Save CMD History
If you frequently need to save command logs, you can automate it using a batch file.
- Open Notepad and paste the following lines:
@echo off doskey /history > "%userprofile%\Documents\cmd_auto_history.txt" exit - Save the file as save_cmd_history.bat.
- After working in Command Prompt, run this batch file before closing it to automatically save your history to your Documents folder.
This ensures you never lose important command sequences again.
Wrapping Up
Viewing your Command Prompt history in Windows 11 is easy once you know the shortcuts. You can use simple tools like arrow keys, F7, or doskey /history to recall commands, or even export them to a text file for later use.
For power users who frequently work with CMD, enabling persistent history in Windows Terminal or creating a batch script for automatic exports can save valuable time.
Once you’ve set up your preferred method, you’ll never have to retype long commands again — making your workflow faster and more efficient.