Home > Articles > Operating Systems

  • Print
  • + Share This
  • 💬 Discuss
From the author of

Issuing DOS Commands

When you enter a DOS command, two sets of parameters determine how the command is carried out. Any parameters or switches that you explicitly type take precedence, of course, but unless you override them, the default values for a command are used.

Throughout this chapter, you've seen the DIR command used as an example. Here's one more:

DIR /P

When you issue the DIR command to see the files on a disk, the currently logged directory is used unless you specify otherwise. Also, all the files in the directory are shown unless you somehow override the default by explicitly specifying a file or group of files. By default, the display of files scrolls to the end without stopping. In the preceding example, the display of all files in the current directory (the default) is used, but the /P switch, which makes the listing pause after each page of filenames, overrides the default behavior of scrolling to the end of the list without stopping.

Figure 3.5 breaks down the different elements that make up the DIR command. As you can see, only two of the switches (/P and /W) are illustrated.

Figure 3.5 The syntax of the DIR command.

Figure 3.6 is a diagram of the DIR command as you might use it. If you are unfamiliar with the anatomy of a command, the following sections explain each of the different parts.

Editing and Canceling Commands

You occasionally might make a mistake when you are entering a command. Because DOS does not act on the command until you press Enter, you can correct a mistake by using the arrow keys or the Backspace key to reposition the cursor and type over your entry. If you need to insert characters into the command line, press the Ins key to turn on the insert mode. After you press Enter, DOS automatically returns to the overtype mode.

If, however, you have gotten way off track and want to cancel what you have and start over, you can press the Esc key, Ctrl+C, or Ctrl+Break.

DOS stores keystrokes that have not yet been displayed in a type-ahead buffer. The idea of the type-ahead buffer is to keep keystrokes from being lost when entered by fast typists, or when a prolonged operation takes the computer's focus away from the keyboard for a moment. If the type-ahead buffer gets filled with keystrokes, your PC beeps when you press an additional keystroke, warning you that you are losing keystrokes. The buffer storage areas also give DOS some special editing capabilities.

Each time you complete a command by pressing Enter, the command is stored in another buffer, the last command buffer. Using the DOS editing keystrokes, you can recall the last command, or you can pull the preceding command line from the buffer and use it again. This feature is helpful when you want to issue a command that is similar to the last command you used or when you mistyped a parameter. Table 3.2 lists the keys you use to edit the input buffer.

Figure 3.6 Issuing the DIR command.

Table 3.2 DOS Command-Line Editing Keys

Key

Action

Tab

Moves the cursor to the next tab stop

Esc

Cancels the current line and does not change the last command buffer

Ins

Enables you to insert characters into the line

Del

Deletes a character from the line

F1 or right arrow

Copies the next single character from the last command buffer

F2

Copies all characters from the last command buffer up to, but not including, the next character you type

F3

Copies all remaining characters from the preceding command line

F4

Deletes all characters from the last command buffer up to and including the next character typed (opposite of F2)

F5

Moves the current line into the buffer but does not allow DOS to execute the line

F6

Produces an end-of-file marker (^Z) when you copy from the console to a disk file


These editing keystrokes come from the earliest versions of DOS. Beginning with version 5.0, there is a better way. The DOSKEY command, usually entered via AUTOEXEC.BAT, loads into memory a program that creates a much larger buffer to store previous command lines. (Refer to the "Command Reference" for the DOSKEY listing.) You can recall these commands by pressing the up-arrow key. The DOSKEY buffer is 512 bytes by default, which is enough on average to store the last 20 commands executed.

→ For a complete reference source for DOS editing keystrokes, see Appendix D, "DOS and DOS Utility Programs' Keyboard Commands," p. 563.

Using Scroll Control

The term scrolling describes what happens as a DOS screen fills with information. When DOS displays text in response to your typing or as a result of a DOS command, the text fills the screen from left to right and top to bottom. As the screen fills, information scrolls off the top of the display. To stop a scrolling screen, press Ctrl+S (hold down the Ctrl key and then press S). Press any key to restart the scrolling. On enhanced keyboards, press the Pause key to stop scrolling.

Using Wildcards in DOS Commands

Almost everyone has at one time played a game, such as poker, that employs wildcards. If you hear the dealer say "Deuces are wild!" you know that cards having the number 2 printed on the face can be substituted for any other card in the deck.

DOS uses wildcards, too. When you're entering DOS commands, you can use wildcards to specify groups of files. DOS recognizes two wildcard characters: the question mark (?) and the asterisk (*), also called star ("star dot star" means *.*).

In DOS commands, the ? represents any single character. The following command produces a directory listing of any files in the currently logged directory that have a filename beginning with the letters LTR followed by up to three characters:

DIR LTR???.TXT

Also, only those files bearing the extension .TXT match and are listed. Thus, LTR.TXT, LTR0.TXT, LTR01.TXT, LTR001.TXT, LTRMOM.TXT, LTR_32.TXT, and LTR999.TXT are listed, but LTRPOPS.TXT or LTR1001.TXT are not.

The * represents any string of characters. For example, *.* represents all filenames with any extension, the default scope of the DIR command. The following command lists all files in the currently logged directory having the extension .DOC:

DIR *.DOC

The following command lists all the files listed by the DIR LTR???.TXT example, as well as filenames not matched by that form of the command:

DIR LTR*.TXT

You should look out for one thing when you're using the * wildcard, however. The following command does not produce the result you might expect:

DIR *LTR.TXT

This example does not list all the .TXT files whose names end in LTR. Rather, it lists all the files having the extension .TXT. The reason is deceptively simple. Because the * can represent up to eight characters in a filename, any string of characters matches *LTR.

After you get the hang of using wildcards to refine the scope of command parameters that supply filenames, you will find that you are well on your way to becoming a DOS power user.

  • + Share This
  • 🔖 Save To Your Account

Discussions

comments powered by Disqus