How to run previous command by history index in Windows command prompt

1

I want to know to how run a previous command in history by index like how it is done in Linux (i.e ![index]).

Yes, F9 in cmd raises a pop up box that allows me to enter in the index, but how do I do it straight form the command-line without the dialog box? Is there a way to do this in cmd without third party downloads?

Additionally, is there a way to display the command history with indexes all well? Moreover, doskey /history displays a list of the previously executed commands however it does not list the indexes too.

coderrick

Posted 2016-09-22T05:38:35.300

Reputation: 111

Answers

1

How do I do it (run by index) from the command-line without the dialog box?

This is not possible with using a 3-party programs.

You could try using clink:

Clink combines the native Windows shell cmd.exe with the powerful command line editing features of the GNU Readline library, which provides rich completion, history, and line-editing capabilities. Readline is best known for its use in the well-known Unix shell Bash, the standard shell for Mac OS X and many Linux distributions. Features

  • The same line editing as Bash (from GNU’s Readline library).
  • History persistence between sessions.
  • Context sensitive completion;
    • Executables (and aliases).
    • Directory commands.
    • Environment variables
    • Thirdparty tools; Git, Mercurial, SVN, Go, and P4.
  • New keyboard shortcuts;
    • Paste from clipboard (Ctrl-V).
    • Incremental history search (Ctrl-R/Ctrl-S).
    • Powerful completion (TAB).
    • Undo (Ctrl-Z).
    • Automatic “cd ..” (Ctrl-Alt-U).
    • Environment variable expansion (Ctrl-Alt-E).
    • (press Alt-H for many more…)
  • Scriptable completion with Lua.
  • Coloured and scriptable prompt.
  • Auto-answering of the “Terminate batch job?” prompt.

Is there a way to display the command history with indexes?

doskey /history displays a list of the previously executed commands however it does not list the indexes.

Press F7 to list the history with indices:

enter image description here

You might also want to look at using:

F5 Scroll through history of typed commands (↑).

F8 Move backwards through the command history, but only display commands matching the current text at the command prompt.

Source syntax-keyboard


Further Reading

DavidPostill

Posted 2016-09-22T05:38:35.300

Reputation: 118 938