Microsoft

TechRepublic community shines again with better command-prompt tips

One of the best and most consistently beneficial sources of information on TechRepublic is the community membership. This simple fact was proven again when the membership came through with improvements to a previously published tip on command prompt history.

One of the primary guiding principles of TechRepublic is that the community is where the knowledge lies. The membership continues to be one of the best and most consistently beneficial sources of information at TechRepublic, and that fact was proven yet again when members chimed in to offer improvements to last week's Windows XP tip on command-prompt histories -- "Avoid Frustration and Display a Full Windows Command-Prompt History."

Original tip

Last week, Greg Shultz showed you how to get a history of the commands typed at the command prompt. The command was simple enough:

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 that my last few commands have been ping commands.

Enhancements

mytmous

Member mytmous offered this enhancement to Greg's tip:

That's a good tip, but I've always just used the F7 key, which will open a window that shows 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 (Figure B).

Figure B

Typing F7 gives you a pop-up window with your command-prompt history.

Kiwi.Dusty

Member Kiwi.Dusty offered this list of command-prompt function keys and their results:

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

paul.harrison@...and greg.ross@... and BrettK

Members paul.harrison, greg.ross, and BrettK tagged teamed to show us a tip that makes switching directories easier at the command prompt. For example, if you don't want to type or can't remember a long folder name, you can use a wild card or the tab key to speed things along.

At the C:\ prompt, type:

cd do*

And the directory will change to:

C:\Documents and Settings
Alternatively, you can use the Tab key instead of the "*" wild card to get the Documents and Settings folder name (Figure C).

Figure C

Hitting the Tab key after typing the first few letters of a long folder name will give you choices.

p.laman@...

Member p.laman@... provided us a link to Microsoft TechNet, which explains many of the commands and parameters you can use with Doskey.

Batch files

Members davids@..., jnickell@..., and particularly philrunninger@... teamed up to write a couple of batch files you can use to log your command-line sessions and then ask for specific information from that log.

Create these two batch files with your favorite text editor and place them in a folder that you can access from the command-line window. I used C:\.

q.bat

@echo off
echo ---------------- %date% %time% ---------------- >> "%userprofile%\cmdHistory.txt"
doskey /history >> "%userprofile%\cmdHistory.txt"
exit

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 "%*"
)
)

After taking care of business in the command-line window, type q.bat instead of typing exit. Now, you can type h.bat with a parameter that will show you the commands that match it. For example:

h.bat ping
Will show you all the ping commands you issued (Figure D).

Figure D

The h.bat file will show you the commands from your log that match the parameter.

Community efforts

Thanks to everyone who participated in the discussion thread stemming from last week's tip. The knowledge, expertise, and professionalism shown in that discussion are greatly appreciated. Never-seen-before tips are few and far between when it comes to Windows XP, but it can be well worth our time to refresh our collective memories about these hidden gems in the operating system.

For your efforts, every member mentioned in this blog post is due a piece of TechRepublic swag. Just send me a private message with your mailing address and I'll hook you up.

Do you have a favorite tip, or possibly an obscure one, that you'd like to share with your peers at TechRepublic? Add them to the discussion thread that follows this blog post or send me a private message explaining it so that I can recreate it.

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

About

Mark Kaelin is a CBS Interactive Senior Editor for TechRepublic. He is the host for the Microsoft Windows and Office blog, the Google in the Enterprise blog, the Five Apps blog and the Big Data Analytics blog.

33 comments
jmcinerney
jmcinerney

If you need to move up a level from where you are try cd .\ and then the tab key AND cd .. to go back up a level

jruby
jruby

One version of the command prompt, possibly in Windows 98, used to allow multiple dots to go up multiple levels in the directory tree. Now you have to type "cd ..\.." to go up two levels, but at one time you could have typed "cd ...". You could go up as many levels as you wanted by typing one more period for each level. I occasionally find myself reverting to that syntax and then wondering why it doesn't do anything.... Jim

samuel.a.dyck
samuel.a.dyck

I do not recall the multiple dot flavor of cd. Of course, there is always the dreaded "del ." which is the same as "del *.*"

jruby
jruby

If you hit F7, and pick an item on the list then hit ENTER, that line will be executed. If you hit the right cursor instead of ENTER, that item will be placed on the command prompt instead of being executed, which gives you an opportunity to make changes before executing the command. Jim /* Still waiting for MY bailout */

eyesak
eyesak

Details - always good to know the details. I tried the F7, then right cursor, I was thinking Right Mouse Click - Tried the Right Directional Arrow on the keyboard "BINGO" that was it. Good to know - could see how that could be useful to then edit what was laid out on the screen. Also - once on the command screen, you can use directional arrow to place your cursor where you want it and edit the line, instead of using the back key, and deleting the line up to a point. Thanks Jim/Jruby Ron/eyesak

jruby
jruby

If you type the first part of a command and then hit F8, you can scroll through your history displaying just the commands that started with what you type. For example, if you type DIR and hit F8 repeatedly, you'll scroll through all the DIR commands in the history, this will display things like: DIR/ad DIR/s *.mp3 DIR x:\HideStuffFromTheBoss Unfortunately, it is case sensitive, so you wouldn't see: dir myresume.doc Jim /* Still waiting for MY bailout */

samuel.a.dyck
samuel.a.dyck

These tips are good if/when you are working within cmd.exe or command.com . I was hoping to see an equivalent for use within Windows.

?vatar
?vatar

Suppose you all know this works exactly the same on Vista and Windows 7, the only exception is that one needs to find the "Elevation Powertoy" for Vista to get the command prompt here context menu for computer. Located here: http://technet.microsoft.com/en-us/magazine/2007.06.utilityspotlight.aspx?pr=blog I just mention this because some folk may not be aware that DOSKEY is still alive and well and not limited to XP and older Windows OSes. Maybe that title should be appended a bit.

308Tom
308Tom

Love it. Unlock real power using your brain and fingers rather than just clicking. But to get there one might consider using CmdHere.inf to rapidly and easily bring up a command window while using Explorer. Just search for CmdHere.inf and install.

chancea
chancea

Personally, I use Windows Key + R to get to the Run dialog, and then type in "cmd" to bring up the command line. That is one of my most-used key combos.

wmarvel
wmarvel

This reminds me of th OLD days when all we had was command prompt!Remember DOS 1.25 and DOS 3.0? Ahhhh.. the good old days!

Gh0stMaker
Gh0stMaker

I remember carrying around the black book - cheat sheet for Dos commands for all the switches..

helpdesk
helpdesk

Excellent tip, never knew these existed (other than the F1)

Cisco-SA
Cisco-SA

The F7 is one I did not know and now I do. Already starting to use it. I like the hard work put in for the q.bat and h.bat but this is standard for anyone who has used a /bin/bash shell in a *nix environment. bash keeps history as far back as you want. For someone who has to slide back and forth between cmd.exe and bash this is a big help. Although DOS/cmd.exe still has long way to go to match the basic power of a /bin/sh *nix shell.

asaw3c
asaw3c

itzz very good,, cuZZ It ZZ working

TonytheTiger
TonytheTiger

Do you have an old (DOS) program that will only output to an LPT printer, but all you have is a USB printer? Simply "share" your USB printer, then: Net use lpt1 \\mymachine\myprinter

Desktop Veteran
Desktop Veteran

If you add the persistent statement at the end it will continue to map after each log on. net use lpt1 \\mymachine\myprinter /persistent:yes This works with drive mappings as well.

computechdan
computechdan

mapping usb to lpt works in win98 as well, so long as you don't attempt to map to an lpt that physically exists, if your program requires lpt1 you will have to disable lpt1 in bios

TonytheTiger
TonytheTiger

in order to map an existing LPT, you have to be an administrator.

worley84
worley84

Using the Tab is even more functional than you mentioned. The Tab key toggles through anything that matches what you type after the CD command. If you just type "CD " then the Tab key, you will go through all your folders. No more typing out "Documents and Settings" at a command prompt. That's a timesaver.

computechdan
computechdan

you forgot to mention that you must type a space after cd before the tab function will work

worley84
worley84

Look closely where it says "CD ". There was a reason for the quotes, so that the space in the command would show. Guess I should have mentioned it, too. Sorry for any confusion.

---TK---
---TK---

that one is going to be useful, thanks!

Mark W. Kaelin
Mark W. Kaelin

I am always on the look out for Windows XP tips, especially tips that have not appeared in this blog before. Have you got a favorite tip that many people don't know, but should? Share it with us. I'll hook you up with swag.

liviu.obreja
liviu.obreja

Go to the properties of the cmd window and check the Quickedit mode check box. click OK and choose "Modify shortcut that started this window". Now you can select with the mouse same way you do in any window. One click with the right button will copy the highlited text. Another one will paste it in the same window or you can use CTRL+V to paste it in a different application. Very convenient....

abduallah
abduallah

Having worked in IT for 40 years, I gravitate to command line functions. They require no looking for the right hidey-hole in Windows to find a desired function. My dream would be for Windows to offer an optional command prompt portal as part of the desktop. I know that you can fire up and leave the command prompt window open, but is is just not the same. Green screens forever!!

jamie
jamie

I have always thought a simple "portal" solution in MS Windows would be this: With the cursor positioned over any blank area of desk top (no matter what window was active, even a doc editor), hitting the space bar opens a cmd prompt "line." Just a simple, one line window. Entering something equally simple, like "c", expands the "line" to a full cmd "window." But if you are only interested in executing .bat, .com, .exe files or utilities, a simple "line" is all you need. Perhaps another key stroke is better than simply pressing the space bar, but it should be trivially easy to bring up a command line.

njmezza
njmezza

To enable opening the command prompt with a quick keystroke, namely ctrl + alt + (key), use the built-in 'shortcut key' option for shortcuts. find or place a shortcut to the command prompt (cmd.exe) in your start menu or on your desktop and and open its properties. In the "Shortcut Key:" box under the shortcut tab, type the key you wish to use with Ctrl and Alt to open the command prompt. This can be used for any shortcut on your desktop or in your start menu. You may also want to check out Mike Lin's Command line, or MCL, available at Mike Lin's Homepage www.mlin.net. This places a single line run/cmd box on the desktop.

troy.d.mccurdy
troy.d.mccurdy

I've always used the "Up" and "Down" arrow keys to scroll through my history of command lines used...