Windows 7 / Getting Started

Command Editing and the History List

Command lines entries can be long, convoluted lists of program names and arguments, like this:

ibmfix -b -ic:\ibm\input\imports\filea.txt c:\ibm\output\impa.dat

Nobody expects you to type something like this without making errors. CMD lets you edit a command before you press Enter so you can correct mistakes without having to retype the whole line.The additional editing functions provided by the optional program DOSKEY in DOS and Windows 9x are standard in CMD. Here are some ways that CMD lets you edit a command under construction:

  • The left- and right-arrow keys let you move the cursor back and forth within the line. Ctrl+left arrow and Ctrl+right arrow move the cursor back and forth by whole words. Home and End move the cursor to the beginning and end of the line, respectively.
  • By default, any characters you type are inserted at the cursor point and the remaining text slides to the right.You can press the Ins key to toggle between insert and overwrite mode. (COMMAND.COM defaults to overwrite mode.)
  • Command lines can extend in length beyond one line on the screen. If you type more characters than can fit on the width of the screen, CMD scrolls the line up.You can scroll to an earlier or later line with the left and right arrows. (COMMAND.COM doesn't let you scroll back to earlier lines.)
  • If you press the F3 key, the command line is filled in with characters from the previously entered command, from the current cursor position to the end of the line.
  • When you're finished editing, you can press Enter with the cursor at any place in the line.

Working with command-line programs can quickly get tedious if you have to type the same command over and over. Imagine typing in commands like this by hand, only to find that you should have typed -a instead of -b and need to do it all over again:

ibmfix -b -ic:\ibm\input\imports\filea.txt c:\ibm\output\impa.dat
ibmfix -b -ic:\ibm\input\imports\fileb.txt c:\ibm\output\impb.dat
ibmfix -b -ic:\ibm\input\imports\filec.txt c:\ibm\output\impc.dat
ibmfix -b -ic:\ibm\input\imports\filed.txt c:\ibm\output\impd.dat

Luckily, the CMD window keeps track of every line you type in, and it's easy to recall a previous command for editing or reuse. Here's how this works:

  • You can press the up-arrow and down-arrow keys to scroll through the list of previously entered commands. If you find one you want to reuse, you can simply press Enter to run it again. Alternatively, you can edit the command using the keys described earlier.
  • PgUp recalls the oldest command in CMD's list; PgDn recalls the most recent.
  • If you press F7, CMD displays a list of recently entered commands.You can select one of these lines and press Enter to reuse it, or you can press Esc to dismiss the list of commands.

CMD has more editing features than I've listed here; these are just the most useful.To see the whole list, click Start, Help, and search for DOSKEY.

Tip: One feature you might want to read is the capability to define macros, which are whole command lines that you can call by typing a short abbreviation or keyword. Unix users know these as aliases and will be happy to know that they're available in Windows.

[Previous] [Contents] [Next]