Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

CMD Command History and Function-Key Shortcuts

Use F1–F9, Doskey history, prefix matching, path completion, line editing, and temporary macros to work faster in Windows Command Prompt.

Table of Contents

CMD has a set of history and line-editing controls that go beyond the usual arrow keys. The F1–F9 commands are supplied by the Command Prompt/Doskey editing behavior: they can copy parts of the previous command, display history, filter it by a typed prefix, and recall an entry by number. These shortcuts are most useful when you repeatedly adjust long paths or command options.

Common keyboard shortcuts in Command Prompt Picture 1

Quick history shortcuts

ShortcutCMD action
Up/Down arrowMove backward or forward through command history
F3Copy the remaining characters from the previous command into the current line
F5Copy a command from the history template and cycle through earlier entries
F7Display a numbered history list; choose an entry with the arrows and Enter
Alt+F7Clear commands from the current history buffer
F8Cycle through history entries that begin with the characters already typed
F9Prompt for a history number and place that command on the line

F7 and F9 work together: press F7, note the number beside a command, close the list with Esc, press F9, enter the number, and press Enter.

What F1 through F6 do in CMD

KeyBehaviorPractical use
F1Copies one character from the previous command at the corresponding positionRebuild a previous command character by character
F2Prompts for a character, then copies from the previous command up to—but not including—that characterReuse the start of a command before a delimiter
F3Copies the remainder of the previous command from the current cursor positionRestore most or all of the previous line
F4Prompts for a character, then deletes from the cursor up to the next occurrence of that characterRemove a section before a known delimiter
F5Copies a command template from historyCycle through prior commands
F6Inserts the Ctrl+Z end-of-file characterSignal end of input to a console program that recognizes it

These keys operate on the CMD line editor's previous-command template. The result can feel unusual until you test it with harmless commands.

Try the function keys safely

Enter these commands one at a time:

echo alpha-beta-gamma
echo one-two-three
dir "%USERPROFILE%"
  1. Press F7 to see the three entries in history.
  2. Press Esc to close the list.
  3. Type ec and press F8 to cycle only through commands beginning with ec.
  4. Press F3 to restore the remaining text from the selected previous command.
  5. Edit the line before pressing Enter.

Common keyboard shortcuts in Command Prompt Picture 2

Display the current history as text:

doskey /history

Save it to a file:

doskey /history > "%USERPROFILE%\Desktop\cmd-history.txt"

The exported history can contain paths, hostnames, usernames, command arguments, or secrets pasted by mistake. Review it before sharing, and do not use command lines to pass passwords or tokens when a safer input method exists.

Change the history buffer size

For the current console process, you can request a larger history buffer:

doskey /listsize=100

This does not create a permanent cross-session shell history. A new CMD process may use its own buffer and defaults.

Create temporary Doskey macros

Doskey can define short aliases for the current CMD session:

doskey ll=dir /a $*
doskey cproj=cd /d "D:\Projects"
doskey history=doskey /history

Examples:

ll "*.txt"
cproj
history
  • $* passes all arguments supplied after the macro name.
  • $T separates commands inside a macro, similar to an ampersand.
  • $G represents output redirection (>) when defining a macro.

Macros are usually session-specific. To load them automatically, use a reviewed macro file and an approved startup method; do not blindly import a macro file because a macro can execute multiple commands.

Everyday line-editing shortcuts

ShortcutAction
Tab / Shift+TabComplete matching file and folder names forward or backward
Ctrl+BackspaceDelete the word to the left
Home / EndMove to the beginning or end of the line
Ctrl+Left/RightMove by words
Ctrl+HomeDelete characters to the left when the command line is not empty; with an empty line, move the viewport to the top of the buffer
Ctrl+EndDelete characters to the right when the command line is not empty; with an empty line, return the viewport to the command line
InsertToggle insert and replace behavior in the Doskey line editor
EscClear the current input line
Ctrl+CCancel a running command when no console text is selected

Why some keys appear not to work

  • A laptop may require Fn+F7 or Fn Lock because the top row defaults to media controls.
  • Windows Terminal can assign its own key binding before CMD receives the key.
  • A program running inside CMD can handle function keys itself.
  • The active window may be PowerShell, WSL, or another shell rather than cmd.exe.
  • Selection or Mark mode changes what arrow and Ctrl keys do.

Confirm the shell by running:

echo %COMSPEC%

A normal CMD configuration reports a path ending in cmd.exe.

History is not a safety net

Recalling a command does not verify that its paths or targets are still correct. Before rerunning del, rmdir, taskkill, disk tools, or an elevated command, inspect the entire line. A small edit in the wrong place can change the scope substantially.

For selection and clipboard controls, see TipsMake's full guide to Command Prompt keyboard shortcuts. The tutorials on opening CMD and common CMD commands cover launch methods and safe examples. Microsoft's Doskey reference documents the function keys, history, and macro tokens.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.