How to use command history in Command Prompt for Windows 10

If you're a frequent user of the Windows 10 Command Prompt, the "command history" feature allows you to view and quickly reuse recent command instead of having to retype them, making your daily tasks more efficient.

In this Windows 10 guide, we'll walk you through the steps to access your command history and export your recently typed command to a file while in Command Prompt.

How to view Command Prompt history with F7

To use the F7 key to view your Command Prompt history, use these steps:

  1. Open Start.
  2. Search for Command Prompt, and click the top result to open the console.
  3. Press the F7 key.

Using the F7 key will open the graphical interface with a list of commands you typed in the current session, even if you mistyped them.

While in the command history, you can use the up or down arrow keys to select the command that you want to reuse. If you want to exit without running any command, press the Esc key.

How to view Command Prompt history with doskey

On Command Prompt, the doskey is a command line tool that recalls previously typed commands, edits command lines, and you can even use it to create macros.

In this case, you can use the command to view a list of the command history from the current session. Here's how:

  1. Open Start.
  2. Search for Command Prompt, and click the top result to open the console.
  3. Type the following command to view the command history and press Enter:doskey /history

The only caveat with this tool is that you can view your current history, but you can't select the command like using the F7 key. However, you can use the arrows and pages keys on the keyboard to cycle and run previously typed commands.

  • Down arrow — Re-enters the next command that you typed. If you hit the arrow key repeatedly, it'll scroll down through the command history currently in memory.
  • Up arrow — Re-enters up the previous command that you typed. If you hit the arrow key repeatedly, it'll scroll up through the command history currently in memory.
  • Page Down — Re-enters the last command from the current session history.
  • Page Up — Re-enters up the first command from the current session history.
  • Esc — Deletes the current content of the console line.

How to export Command Prompt history to file

Unlike the Linux console, command history is only available for the current session. If you close Command Prompt, it will also clear the history, but you can the doskey command to save the history of the commands you typed to a file.

To export your command history, use these steps:

  1. Open Start.
  2. Search for Command Prompt, right-click the top result, and click the Run as administrator option.
  3. Type the following command to save the command history and press Enter:doskey /h > c:\cmd_history.txtIn the command, change the c:\cmd_history.txt for the path and name of the file you want to use to export the current history.

Once you've completed the steps, the Command Prompt history will be saved on the location you specified.

We're focusing this guide on Windows 10, but command history for Command Prompt has been around for years, which means that you can also use this feature on Windows 8.1, Windows 7, and previous versions.

More Windows 10 resources

For more helpful articles, coverage, and answers to common questions about Windows 10, visit the following resources:

Mauro Huculak

Mauro Huculak has been a Windows How-To Expert contributor for WindowsCentral.com for nearly a decade and has over 15 years of experience writing comprehensive guides. He also has an IT background and has achieved different professional certifications from Microsoft, Cisco, VMware, and CompTIA. He has been recognized as a Microsoft MVP for many years.

Latest in Windows 10
Windows 10 Find My Device
How to enable Find My Device on Windows 10 to recover your PC if it's ever lost or stolen
Outlook Client Hero
Microsoft just made Windows 10 worse, and there's (almost) nothing you can do about it
Windows 10 Start menu on HP ZBook Studio G4
Microsoft will retroactively downgrade this part of Windows 10 next month
Former Microsoft Executive Vice President Terry Myerson stands in front of a presentation about Windows 10
Microsoft addresses the 'elephant in the room,' discusses upcoming end of Windows 10 support
Surface Hub 2S
Windows 10 for PCs is not the only version of Windows to reach end of support this year
Windows Insider program settings
Microsoft shuts down the Windows 10 Beta Channel just five months after reopening it
Latest in How-to
Atomfall
Can I play Atomfall on Steam Deck, ROG Ally, and other gaming handhelds?
The First Berserker: Khazan
Is The First Berserker: Khazan on Xbox Game Pass?
Clair Obscur: Expedition 33
Is Clair Obscur: Expedition 33 on Xbox Game Pass?
A close-up of Hazel in South of Midnight
Is South of Midnight on Xbox Game Pass?
Atomfall screenshot
Atomfall: How to grab the best melee weapon and melee perk right away
Atomfall District B
Atomfall: How to open District B, get inside the Robot Facility, and grab the Signal Redirector