15

How do I export the history from the Windows command line to a text file?

I think you can do it in Linux as something like "history >filename.txt", but how do you do it in Windows? I'm a geneticist, and I want a record of exactly what programs I've run for my lab book.

I'm using Windows 7 64 bit if it makes a difference.

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
Kirt
  • 7,001
  • 17
  • 51
  • 61

3 Answers3

23

You can use the doskey command to do this:

doskey /HISTORY > history.txt
heavyd
  • 62,847
  • 18
  • 155
  • 177
  • doskey is not a command, it is external utility. – Andrejs Cainikovs Sep 29 '10 at 12:29
  • 1
    @Andrejs, actually its built into `cmd.exe`. See the [Wikipedia article](https://secure.wikimedia.org/wikipedia/en/wiki/DOSKey): *In current Windows NT-based operating systems DOSKey's functionality is built into cmd.exe, although the DOSKey command is still used to change its operation.* – heavyd Sep 29 '10 at 12:32
  • seems i need to include the doskey bit? – Kirt Sep 29 '10 at 12:37
  • also, is there a way i can get it to include information printed to the screen as well? – Kirt Sep 29 '10 at 12:37
  • To see it on the screen, use just `doskey /history` – heavyd Sep 29 '10 at 12:43
  • thanks but, no i mean i need that info printed to a file – Kirt Sep 29 '10 at 12:45
  • @Bec, I guess I'm not quite understanding what you're asking for. My original answer will output the command line's history to the file *history.txt*, what exactly do you mean by "printed to a file"? – heavyd Sep 29 '10 at 12:59
  • ah yeah that worked ok, but only for commands i'd typed, info printed to screen from scripts etc. not included. guess i should just adapt my script to make a log.txt file but would be handy to know for when using someone else's script which i'm less able to adapt – Kirt Sep 29 '10 at 13:35
  • You mean you want to save the command history AND the console output? – Andrejs Cainikovs Sep 29 '10 at 18:54
  • @heavyd: Thanks for update, I was not aware of that. – Andrejs Cainikovs Sep 29 '10 at 18:54
  • anyway to get complete history, not the one executed in the current window/cmd. ? – coding_idiot May 15 '15 at 18:55
  • @coding_idiot the history is not saved, so no there is no way to get more than just the current window – heavyd May 15 '15 at 19:06
0

clink provides features that are similar to GNU readline and bash. In addition to history, you get something that's very similar to the navigational power that you get in Unix.

Ehtesh Choudhury
  • 1,478
  • 1
  • 15
  • 13
-1

To export the history, I was able to simply right click the window, click "select all" then CTRL-C to copy. I then CTRL-P pasted into a text editor.

You'll want to max out the screen buffer height to 9999 when you start your session because you'll only be able to copy text that's showing in the buffer. You set the screen buffer height by right clicking the title bar of the cmd window, select properties, click the layout tab.

Bret Leduc
  • 31
  • 3
  • Please read the question again carefully. Your answer does **not** answer the original question. OP want's to copy the command history not the command output (screen contents) – DavidPostill Feb 18 '17 at 23:09