Home Windows How to Use Command Line History on Windows Command Prompt

How to Use Command Line History on Windows Command Prompt

Linux users who used to using the command line on a daily basis must get clumsy when switching to Windows. On Linux, you can effortlessly use the previous commands you typed by just pressing the up and down arrow keys on the keyboard thanks to the history feature. On Linux, the history feature applies not only for the current session but also for previous sessions. The different story goes on Windows.

The Command Prompt on Windows also offers the history feature. However, it doesn’t remember commands from the previous sessions. This means you won’t be able to reuse the commands you used on previous sessions as you can do on Linux.

Speaking of the command line, Windows users seem rarely enough to use the command line because on Windows everything is GUI-based. But, some tasks — like checking internet connection using PING — keep way easier using the command line.

In case you new to the command line, this post will cover the use of history feature on Command Prompt, a standard tool to execute the command line on Windows.

How to use the command history

You can use keyboard shortcuts to show the command history on Command Prompt. Following are the shortcuts you can use.

  • Up arrow – to view the previous commands you have typed within a session. Press the up arrow key repeatedly to walk through your command history.
  • Down arrow – the opposite to up arrow. To view the next command you have typed. Press the key repeatedly to walk through your command history.
  • Page up – to view the first command you used in a session.
  • Page down – the opposite to page up. To view the last command you used in a session.
  • Esc – to clean the command line.
  • F7 – display your command history in a pop-up. Use the up and down arrow keys on the keyboard to select a command and hit Enter to use it. Press Esc to close this pop-up.
  • F8 – You can use F8 to search for previous commands that match the text on the current command line. For instance, if you want to search for a command that begins with the “t” letter, you can type “t” on the command line and press F8 repeatedly to view recent commands begin with “t”.
  • F9 – You can use this shortcut to reuse the command based on its history number, which you can figure out using F7. For instance, on the F7 execution above, the 8th order belongs to PING. Simply press F9, followed by 8 and hit Enter to reuse the PING command.

If you want to print all of the commands you have used within a session, you can type following command.

doskey /history

The command above will display the list of the commands you used within a session. Much like F7, but not in a pop-up.

How to clear and save your command history

As we have mentioned earlier, the Command Prompt of Windows doesn’t record the commands you have typed on the current session for the next sessions. Everything will be lost once you close the session. So, you can simply close your current session to clear the command history.

If you want Command Prompt to forget everything you typed on the current session, you can set the history size to 0 with the doskey.

doskey /listsize=0 c

By setting the history size to 0, you won’t be able to use shortcuts like F7, arrow keys, F8, and other shortcuts mentioned above.

You can use cls to clean up Command Prompt.

cls

If for a certain reason, you want to save your command history into a text file, you can use doskey. Following is the example.

doskey /history > C:\Users\name\Documents\commands.txt

The command above will save your command history to a text file called “commands.txt” on the Documents folder on your Windows account.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most-read this week