Home > Windows

How to View Command Prompt History in Windows 10/11

In this guide, we will show you different methods to view the Command Prompt history on your Windows 10/11 PC. Likewise, we will also show you how to save the command history as a TXT, HTML, CSV, or RTF file. The CMD window needs no introduction of sorts. While the tech giants seem to be pushing the users towards adopting the PowerShell, most of the users are contained with the evergreen Command Prompt. There could be quite a few reasons for the same.

For example, Powershell usually requires appending a period and slash before most of the commands, which is not the case with CMD. Along the same lines, the latter is a tad faster in opening as compared with its counterpart. Well, the perks with using the CMD are aplenty. And since it is used for executing such a plethora of commands, users generally wish to get hold of the history of the commands that they have input till now.

This will then help them to directly recall any of their earlier commands that they have typed in, thereby negating the need to manually type them again. Along the same lines, it also gives them a rough idea as to which of the commands they have dealt with till now. In this regard, there do exist quite a few methods through which you could view the Command Prompt history on your Windows 10/11 PC. And this guide shall make you aware of just that. So without further ado, let’s get started.

Can I View Command Prompt History of Previous Sessions?

how to view command prompt history

So first and foremost, let’s address the elephant in the room- you could only view the command prompt history of the current active session. Hence, if you have input a few commands and then closed the CMD window, then those commands wouldn’t be available the next time you view the history.

I know this might have infuriated quite a few users, but this is how things stand as of now. So the next question that you might ask is that we already knew that one could view command prompt history in Windows 10/11 via the Up and Down arrow keys, so how would this guide prove to be beneficial.

Well, while the arrow keys are indeed a solution, but they aren’t the most convenient ones. In this guide, I will show you the steps to view the history with a touch of GUI, which would also allow you to directly pick up the desired commands from the long list of all your previous ones.

Likewise, we will also show you the steps to copy-paste the previous commands using just a single function key. The entire process wouldn’t involve a mouse or trackpad. Then the ending bit of this guide will show you the instructions to save the command history as a TXT, HTML, CSV, or RTF file. Follow along!

NOTE: The below tips require the use of Function keys, such as F7, F2, etc. If your Function keys already have a secondary function attached, such as volume increase/decrease, brightness control, etc, then you would have to additionally press the Fn key along with the associated Function key. So if you come across the key F3, then in your case it would mean pressing the Fn and F3 keys together.

How to View Command Prompt History with GUI?

how to view command prompt history

To view all your executed commands during this session with a hint of GUI, just press the F7 key once. It shall bring up a list of all the previously entered commands in a box. Select the desired one using the Up or Down arrow key and then hit the Enter key to input it in the CMD window.

How to Access Command Prompt History

view command prompt history via F9

  1. When you pressed the F7 key, each of these commands was assigned a numerical position (starting from 0).
  2. So if you wish to recall any of them, then you would have to make use of the F9 key.
  3. So press F9 and it shall bring up the Enter Position box.
  4. Type in the desired position in that box and hit Enter.
  5. The command at that position will be written in the CMD window and you could then execute it via the Enter key.

How to View Command Prompt History as a List

If you want to get hold of the command’s history in a list, then just input the below command and hit Enter:

doskey /History

how to view command prompt history

How to Search Specific Portion of a Command

Sometimes, you might have executed quite a long command but don’t remember every word of it now. Well, not an issue as you could recall that command using any single word (or even a single alphabet!) from that command. To do so, you need to press the F8 key once, then type in the desired alphabet or word, and again press the F8 key to bring up the result.

However, it will only bring one result at a time. So if you wish to cycle through the results, you will have to keep on pressing the F8 key every time until you land up on the required result. As an example, let suppose your CMD history has the following commands:

ping -4 google.com
doskey /History

Now, if you don’t remember the entire command, but have a clue that it contains the alphabet p, then press the F8 key, type in p, and again press the F8 key. It will bring up the first result: ping -4 google.com. If that’s not what you were looking for, then again press the F8 key and it shall bring the next result: Arp. If this is what you were looking for then just hit Enter to execute this command.

How to Copy Commands from the Command History

Using the F1 key, you would be able to copy one character at a time from the previous command that you had executed. So if the last command was calc, then you would have to press the F1 key four times to type in the entire ‘calc’ command. However this method is quite time-consuming, so let’s check out what else do we have at our disposal.

You could also copy-paste the contents of the previous command, just before a specific character. This could be done via the F2 key and then signify the last character up to which the commands should be copied. For example, suppose the last command you entered was ping google.com. So if you type in F2 and then the letter l, then everything before l would be printed. Hence the output will be ‘ping goog’.

How to Save Command Prompt History in a File

You may use the below command to save the CMD history in a text file:

doskey /h > c:\command_history.txt

Here the file will be named command_history and saved in the C drive. You could change the location as well as the name of the file as per your convenience. Likewise change the extension from txt to html, csv, or rtf, depending on which format you want the file to be saved. For example, if you want to open the CMD history in a browse and save it in HTML format, then use the below command:

doskey /h > c:\command_history.html

So with this, we round off the guide on how you could view the Command Prompt history on your Windows 10/11 PC. We have shared numerous approaches towards the same. Likewise, we have also shown you the steps to save the history in your preferred format. If you have any queries related to any of the aforementioned methods, do let us know in the comments section below.