Is there a global, persistent CMD history?

Solution 1:

Not natively but check out: http://mridgers.github.io/clink/ , makes cmd.exe much more productive. Quoting features from the project page:

Powerful Bash-like line editing from GNU's Readline library.
Superior path completion (TAB).
Paste from clipboard (Ctrl-V).
Support for the completion of executables/commands, and environment variables.
Undo/Redo (Ctrl-_ or Ctrl-X, Ctrl-U)
Improved command line history.
Persists across sessions.
Searchable (Ctrl-R and Ctrl-S).
History expansion (e.g. !!, !<string>, and !$).
Scriptable completion using Lua.

Solution 2:

No, Windows command prompt history can't be saved when a session ends.


Solution 3:

Massimo is correct that your command prompt history does not persist across sessions. You could manually grab this before closing your prompt by typing doskey /history > history.txt

Or... you could use PowerShell as your CMD prompt, and follow this post to persist your history across sessions.


Solution 4:

You can use 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.

Easiest way to install clink is using chocolatey. Once you install chocolatey, you can install clink by typing

choco install clink

Starting from the next time you start cmd.exe, it should store history across sessions.


Solution 5:

It is possible to save the current history to file,

`$ doskey /history > somefile.txt`

But it seems there is no way to load it back as history. It is possible only to use a command line argument to load and execute all lines,

cmd.exe /K somefile.txt

, what can be useful to load a list of doskey macros. This invocation could be included in a shortcut so you don't need to type it everytime; this reference has some additional info on this approach.

There is a similar question on Superuser that bring some alternatives, including clink, as suggested by @RobertBak.