DOS Fundamentals

A brief overview of essential DOS commands, characters, devices, and variables

Ahh, the fun I have at work while experimenting with the command line. I will be the first to admit that I understand very little of DOS, especially when considering the scope of its functional capacity. Nonetheless, I am taking the time to chronicle a few interesting DOScoveries here in this article, as well as in at least a couple of others (see related articles section at the end of this article).

The first thing that I should mention is that there are at least several different entities commonly referred to as "DOS". Windows 98SE and earlier run on the MS-DOS kernel, which is directly accessible by pressing the F8 key repeatedly (after the beep) during computer startup. Windows 2000, Windows XP, and beyond do not run on the MS-DOS kernel, but do provide two MS-DOS-like programs, the command prompt Cmd.exe, and the MS-DOS emulator Command.com. For more information, you may want to explore the difference between Cmd.exe and Command.com before diving in..

File naming conventions used in DOS

All files represented via DOS consist of a root name containing one to eight characters. File names may also include an extension name containing one to three characters. A period always separates the root name from the extension. The root name may not match any device name. Here is a generalized example:

filename.ext

Should look relatively familiar. File names exceeding eight characters in length are truncated with a tilde ("~"). For file names, certain characters are allowed, while others are not:

Acceptable characters
A-Z a-z 0-9 $ # & @ ! ( ) - { } ' ` _ ~
..plus the period, which separates root name and extension
Unacceptable characters
| < > \ ^ + = ? / [ ] " ; , * : %
..plus control characters and blank spaces

Characters used at the command line

Here are a few important commands that are used frequently at the command line:

  • . = current directory
  • .. = up one directory level
  • *.* = all files in current directory
  • *. = all extensionless files
  • * = wildcard for any/all characters/files
  • ? = wildcard for any single character
  • \ = root directory of current drive
  • / = switch prefix
  • - = switch prefix
  • > = redirects output to (overwrite) a file or device
  • >> = redirects output to (append to) a file or device
  • < = directs data from a file or device to a program or device
  • << = directs additional data from a file or device to a program or device

Environmental variables available via the DOS command prompt

Environmental variables are invaluable tools for manipulating data in DOS. Here are a few of my favorites:

System-generated upon Windows startup:

  • %DATE%
  • %TIME%
  • %SYSTEMROOT%
  • %COMPUTERNAME%

System-generated upon user login:

  • %USERNAME%
  • %USERDOMAIN%

Local machine variables for all users:

  • %PATH%
  • %HOMEPATH%
  • %HOMEDRIVE%

To configure additional local and/or user variables (or edit existing ones):

  • Windows NT » Control Panel > System > Environment tab
  • Win2K / XP » Control Panel > System > Advanced tab > Environment Variables button

Computer devices available via the DOS command prompt

Here are a few of the more useful and/or common computer devices available at the command line:

  • COM1 = Serial and/or infrared ports
  • CON = Console (display and keyboard)
  • LPT1 = Line printer (via parallel port)
  • NUL = Null device (virtual blackhole)
  • PRN = Printer (serial or parallel port)

Copy and paste command-line text via mouse

This is great — you can copy and paste command-line text using your mouse. To copy text within the DOS screen, hold the left mouse button and select the desired text, then right-click to copy the highlighted text to the clipboard. To paste the copied text within the DOS screen, simply right-click again.

Function keys available at the DOS command prompt

Here is a nice list of functional commands available during the command prompt session (via Cmd.exe):

  • F1 = Sequential, individual repeat of previously entered characters
  • F2 = Copies any number of characters from the previous command line
  • F3 = Repeats the contents of the previous command line
  • F4 = Deletes any number of characters from the previous command line
  • F5 = Return to the previous command line
  • F6 = Enters the characters ^z (CTRL+z), indicating "end of file"
  • F7 = Displays a history of command-line entries for the current session (50-line cache)
  • F8 = Sequentially displays previous command-line entries
  • F9 = Enables user to recall previous command lines by number (0 = first line)
  • F0 = Just seeing if you were paying attention!

Basic DOS commands

Have fun with your command line with these fabulous functions:

  • CD = CHDIR (change directory)
  • CD . = Move to the same directory
  • CD .. = Move to the parent directory
  • CD \ = Move to the root of current drive
  • CD x = Move to the "x" drive/directory
  • COPY x y = Copy file "x" to "y"
  • XCOPY x y = Copy file or directory "x" to "y"
  • DEL = ERASE (delete files)
  • DEL folder = Deletes all files within "folder"
  • DEL file = Deletes all files named "file"
  • DEL . = Deletes all files within current directory
  • DEL *.* = Deletes all files within current directory
  • RD = Removes (deletes) an empty directory
  • REN x y = Rename file "x" to "y"
  • DIR = Display contents of current directory
  • DIR /W /P *.* = Display all contents one screen at a time
  • DIR | more = Display all contents one line at a time
  • DIR /? = Provides syntax info and complete list of all DIR parameters
  • Z /? = Provides syntax info and complete list of all parameters for Z
  • TYPE file = Display the contents of the file "file"
  • TYPE file | more = Display the contents one line at a time
  • Q = Escapes sequential display of contents (i.e., the "more" parameter)
  • ECHO = Send command line input to display (by default)
  • MOVE = Moves files and renames files and directories
  • MOVE x y = Move or rename "x" to "y"
  • EDIT = Launch the MS-DOS text editor (the DOS version of notepad.exe)
  • EXIT = Exit the DOS command prompt