Windows

Avoid frustration and display a full Windows command-prompt history

Get a complete list of every command you have issued in a particular session with a simple single command. Greg Shultz shows you how in this tip.

If you often work from a Microsoft Windows command prompt, chances are you know that you can cycle through a list of all the commands that you've typed in a particular session using the up and down arrows on your keyboard. You can also change the size of this history list by clicking the command button in the upper left corner, selecting the Properties command, and then changing the buffer size number on the Options tab under Command History.

By default, the buffer size is set to 50, which means that the command history can potentially contain a lot of commands, making it difficult to cycle through all the commands that you've typed by using the up and down arrows on your keyboard. However, there's an easier way to see all those commands.

At the command prompt, enter the following:

doskey /history
You'll see a full listing of all the commands that you've entered in a current session (Figure A).

Figure A

A list shows my last few commands have been ping commands
Note: This tip applies to Windows XP Home, Windows XP Professional, and Windows Vista.

Stay on top of the latest XP tips and tricks with TechRepublic's Windows XP newsletter, delivered every Thursday. Automatically sign up today!

About

Greg Shultz is a freelance Technical Writer. Previously, he has worked as Documentation Specialist in the software industry, a Technical Support Specialist in educational industry, and a Technical Journalist in the computer publishing industry.

49 comments
peter.p.harper
peter.p.harper

Power of doskey /history is really revealed when the command is: doskey /history > \ filename.txt can then be edited and saved as and the whole command sequence executed as often as necessary. Pete H

yesveekey
yesveekey

I call it JIT; just in time. I was just about searching how to increase the dos command history and to my surprise techrepublic forwarded me this blog. Thanx a ton. It was pretty useful for me. Vijay

davids
davids

Create a file called q.bat and put it in c:\windows\system32 with the following: @echo off echo %date% %time% >> c:\cmdHistory.txt doskey /history >> c:\cmdHistory.txt exit Then when you are finished with your cmd sessions always hit q and enter to finish. Then you will have a running log of all the commands that you have run.

BrettK
BrettK

This may be comomnly known, but use the tab key to complete directories/files you're using in a command. You can cycle through similar dirs/file by repeatedly hitting the tab key.

mytmous
mytmous

That's a good tip - but I've always just used the F7 key, which will pop-up a window showing the list of commands. This also allows you to simply use the arrow keys and hit ENTER on one of the commands if you need to reuse it.

Mark W. Kaelin
Mark W. Kaelin

Have you got a favorite Windows tip that you'd like to share with us?

jnickell
jnickell

That's a start and better than default, but I don't think that the full list would be accessible from within doskey. It would just be an external reference? Do you have any ideas on how we could wrangle that?

randy
randy

this simple command turned out to have some really coll stuff

luther7
luther7

Thanks for this link, very good information for DOSKEY here.

melias
melias

Thanks for that link. One of my Favorites now.

Dirk Klassen
Dirk Klassen

...and it even works like this: *.exe[tab] goes through all executables in the current directory. Very useful if you have lots of files with similar names but different extensions, and you only want to run the executable.

pgovil
pgovil

Thanks for the tip and your modest response. That F7 is slick

#1 Kenster
#1 Kenster

I had forgotten about the F7 key, it's a cooler tip than the doshistory. Been awhile....

antonio.barra
antonio.barra

Excellent tip, Mytmous... I didn't knew about the F7 key, that is really a fully geared command line history manager... Home, End Page Up and Page Down work, besides the arrow keys; writing any char cycles thtough the commands that begin by that char; and pressing the left or right arrow keys, instead of Enter, pastes the command in editable form, instead of executing it. It works at least with Windows XP and 2003, will check it on Vista too.

Mark W. Kaelin
Mark W. Kaelin

Now, that is the kind of tip we are looking for. Thank you for passing it on. Anyone else have a favorite tip to share.

Andrew Caple
Andrew Caple

Thanks for that. I didn't know about F7, that will make things alot easier.

dmm99
dmm99

Probably most people know that, but if you didn't, that will save you a LOT of backspacing!

rkanderson
rkanderson

Every so often I need a text list of files in a folder or drive to document a project. Some years ago I came across this DOS tip: c:\[whatever path to whatever folder]dir [one space]>[one space]filename.txt example C:\Nfiles\dir > Nlist.txt The Nlist.txt file will appear in that folder and it will list all N files in that folder, along with file size, dates, etc. There may be a Windows app that does this in a prettier fashion, but I don't know what it is, and this works well enough for my purposes. Obviously this works for other drives, etc. I'm getting an education from the rest of these posts! Thx to all for the info. Cheers!

lfloyd
lfloyd

Here is the help file for the DosKey. Edits command lines, recalls Windows XP commands, and creates macros. DOSKEY [/REINSTALL] [/LISTSIZE=size] [/MACROS[:ALL | :exename]] [/HISTORY] [/INSERT | /OVERSTRIKE] [/EXENAME=exename] [/MACROFILE=filename] [macroname=[text]] /REINSTALL Installs a new copy of Doskey. /LISTSIZE=size Sets size of command history buffer. /MACROS Displays all Doskey macros. /MACROS:ALL Displays all Doskey macros for all executables which have Doskey macros. /MACROS:exename Displays all Doskey macros for the given executable. /HISTORY Displays all commands stored in memory. /INSERT Specifies that new text you type is inserted in old text. /OVERSTRIKE Specifies that new text overwrites old text. /EXENAME=exename Specifies the executable. /MACROFILE=filename Specifies a file of macros to install. macroname Specifies a name for a macro you create. text Specifies commands you want to record. UP and DOWN ARROWS recall commands; ESC clears command line; F7 displays command history; ALT+F7 clears command history; F8 searches command history; F9 selects a command by number; ALT+F10 clears macro definitions. The following are some special codes in Doskey macro definitions: $T Command separator. Allows multiple commands in a macro. $1-$9 Batch parameters. Equivalent to %1-%9 in batch programs. $* Symbol replaced by everything following macro name on command line. You will notice several other options.

rsp
rsp

Great article. In addition one can use: doskey /? to view list of all doskey commands, including macros, which can be edited and stored in a text file. This file can be pre-loaded every time a command window is opened by creating a shortcut with the command line something like: %SystemRoot%\SYSTEM32\cmd.exe /k doskey /macrofile=c:\temp\macros

tcsmith
tcsmith

I always hate the location of the command prompt moving horizontally across the page, depending where one actually is in the directory tree. I have a better idea, one which I starting using back in 1980 on my Data General C-350 and subsequent minis. Try this: C:\WINDOWS\system32\cmd.exe /k "prompt $t - %computername%$_$p$_$g " Put it in the ( Target ) field of your shortcut. I also change the color to a white background with blue text. ( It's easier on my eyes. ) And QuickEdit Mode is handy as well. Tom

Kiwi.Dusty
Kiwi.Dusty

F1 retypes the previous command one character at a time F2 brings up a dialog and asks "Enter the char to copy up to:" F3 retypes the last command in full F4 brings up a dialog and asks "Enter char to delete up to:" F5 as for F3 F6 Print EOF character (Ctrl+Z) F7 brings up a dialog of all the recent command history F8 brings up each of the most recent commands, one at a time F9 brings up a dialog and asks "Enter command number:"

saved2serve
saved2serve

Here is a list of lots of shortcuts you can run from the Run cmd: http://www.techmetica.com/howto/how-to-make-shortcuts-to-control-panel-pages-in-vista/ I use the free AutoHotKey utility which easily enables you to launch apps (simultaneously if you want) and even URL's using the Windows key (#)and other keys (^ =Ctrl) (! = Alt) like, #C::Run control.exe #+r::Run regedit.exe #+M::Run C:\Windows\msconfig.exe #!S::Run C:\Windows\system32\restore\rstrui.exe #!C::Run C:\Windows\system32\cmd.exe #U::Run C:\Windows\System32\appwiz.cpl #+S::Run C:\Windows\System32\services.msc And i am sure most know that System Properties can be reached by the Windows key + Pause/Break combo, which shtct is just one of many: http://support.microsoft.com/kb/126449 Pause/break, for those who do not know, will pause the boot process before the OS begins loading, useful in some cases if you need to read things. Hitting F12 during booting up on some systems will enables you to choose from what HD you want to boot from. What SysRq was used for is before my time on PCs.

ghabgood
ghabgood

Very useful... Big credit to mytmouse for the F7 tip but biggest credit must still go to Mark W. Kaelin for starting this great thread in the first place. From acorns grow... Thank you :-)

mcvik
mcvik

Thanks for the tip. It will make it easier for me.

chavarinderion50872
chavarinderion50872

DOSKEY should run automatically when you start the Command Prompt. There should be no reason to have to invoke it, unless you need to reset to defaults. This applies to XP... Open up a Command Prompt, click in the upper left hand corner on the little Command Prompt icon. On the menu that pops up, click on Defaults. Check to see if buffer size has 50, check that the Number of buffers is 4. Click OK.

jnickell
jnickell

Anyone know of a way to get Windows CMD prompts to save history across multiple sessions, like Linux and Mac OS X? That would save a lot of frustration.

bkamhi
bkamhi

Do you paid residuals for re-publishing your tip from 2007?

philrunninger
philrunninger

Put this text in a batch file, h.bat, and use it instead of doskey /history. You can specify arguments to search the history. To list all your ping commands, for example, enter the following: C:\>h ping C:\Documents and Settings\Phil>type q.bat @echo off echo ---------------- %date% %time% ---------------- >> "%userprofile%\cmdHistory.txt" doskey /history >> "%userprofile%\cmdHistory.txt" exit C:\Documents and Settings\Phil>type h.bat @echo off if %1. == . ( type "%userprofile%\cmdHistory.txt" 2> nul echo ---------------- %date% %time% ---------------- doskey /history ) else ( if /i %1. == /edit. ( start "Revising History..." "%userprofile%\cmdHistory.txt" ) else ( echo ------------------------------------------- Previous Windows type "%userprofile%\cmdHistory.txt" 2> nul | findstr /i "%*" echo ------------------------------------------------ This Window doskey /history | findstr /i "%*" ) ) Now the only thing left is to make all this history available from F7 or the arrow keys. But there's always Copy and Paste, made easy with the QuickEdit Mode option in the Command Window Properties - click, drag, right click (to copy), right click (to paste). Edited: 1. Fixed a bug - wasn't filtering previous windows' history. 2. New functionality: /edit lets you periodically clean out your history file using your default .txt file editor. 3. Moved history file to user profile folder. Requires a new q.bat (included above).

dmm99
dmm99

accidental double post

Simon Neil
Simon Neil

...and I had forgotten about DOSKEY too. I need to have my brain defragged to bring some of this useful stuff back to the front again.

paul.harrison
paul.harrison

If you've got a long directory to get to, you can use a wildcard. e.g. at c:\, then "cd do*" should take you to "Documents and settings"

jolivenom
jolivenom

I never new about the F7 key. Thanks for that excellent tip.

me
me

doskey /history > history.txt would there be a way to add this on closure of the dos window?

jstribling
jstribling

If you knew anything about Internet publishing, you would know that residuals are usually not a factor. Maybe the guy's wife just had a baby or something and he had to pull a column out of the archives this time around. Please give him, and us, a break. I appreciated the tip as I had never seen it before .

Mark A. Lewis
Mark A. Lewis

Some of us have not had the opportunity to read this tip yet. I recently signed up for these tips and this is the first time I've read it. The command looks very helpful.

Mark W. Kaelin
Mark W. Kaelin

But, to change the subject, have you got a new tip you'd like to share - one that we haven't done before.

william.xu
william.xu

eg. cd \wind[tab] it is much better than widecard.

paul.harrison
paul.harrison

Good point. But the wildcard is better if traversing multiple dirs. e.g. cd \wind*\he* should get you c:\windows\help, but note that if the wildcard produces more than one match, this won't work

gross
gross

Instead of the wildcard just hit tab so C:\ cd do and enter will bring you to documents and settings.

AC2
AC2

doskey /history >> history.txt I believe that should append to the file.

tonycopp
tonycopp

These are the days It always seemed that Windows is like an inverted pyramid balancing on a tiny bit of DOS that suffers mightily from bloat..some bit of code M$ appropriated and later welded to whatever they grabbed from Xerox PARC..something the Dali might paint whereas the marketing is more Hieronymus Bosch. All in all, the greatest recycling effort ever in IT.

antonio.barra
antonio.barra

Well... DOS is almost as good as dead... But the command line, that is alive and kicking a lot!

dlcomell
dlcomell

I agree! Great tip! Thank you so much. For those who are in Vista with programmable keyboards, it works best to go to the DOS prompt. F7 make work for some folks but not all which is why Greg always says to go to the DOS prompt before invoking a command. And people think DOS is dead. Now those were the days....:-)

Editor's Picks