Older Operating Systems

Class Notes # 4 DOS Commands September 16, 2003

The .COM is one of the files loaded into memory when DOS boots up. COMMAND.COM is a command interpreter that acts as your interface to DOS services. COMMAND.COM displays the DOS prompt used to indicate that the computer is ready for you to use. COMMAND.COM takes the characters that you the DOS prompt and turns them into an action.

DOS recognizes and responds to over 80 commands. The most commonly used commands are contained within the DOS command interpreter, COMMAND.COM. The commands provided by COMMAND.COM are called internal commands. For example, the and command are internal commands. Other commands are stored as utility programs in a on your hard disk. These stored commands are not built into the command processor and are therefore called external commands. For example, the command is an external command and is a located in the DOS directory.

The syntax for most DOS commands are:

Commandname drive/files switches or Commandname sourcefile targetfile switches

For example: COPY A:myfile.txt C:yourfile.txt

Many users are confused about the way the slashes and back slashes are used in commands. The two simply rules are: • (\) are used as separators when specifying directory and file information. Example, COPY A:\files\myfile.txt C:\files • Slashes (/) are used as signals to DOS that the next character is a command-line switch. DIR/W

To access on-line for the use of a particular command, use one of the following procedures from the DOS prompt: • Type the DOS command, followed by the switch /? (example: DIR/?) • Type HELP, followed by the DOS command (example: HELP DIR)

Wildcards When you’re entering DOS commands, you can use wildcards to specify groups of files. DOS recognizes two wildcard characters: question mark (?) and the asterisk (*). The question mark represents a single character. For example, DIR LTR???.TXT produces directory listing of any files in the current directory that have a file name beginning with the letters LTR followed by up to three characters. Also, those files have the TXT extension.

1 The asterisk represents any string of characters. For example, DIR *.* represents all file names and any extension.

Files To provide and retrieval, the must provide a common method for file storage and retrieval so that any software package can access information easily and quickly. DOS provides these services without you having to know the internal details of how the disk works and why.

When a file is created, either by your software, or a DOS file service routine, information about the physical location of the file is stored in a FAT (File Allocation Table), is similar to a book’s table of contents. DOS places the name of each file and its attributes in a special structure called a directory. Listed below is the rules for creating a file in DOS: • Each file name in a specific folder must be unique • A name of one to eight characters, an optional extension of one to three characters, and a period between the name and extension (if an extension is used) • The file name may contain: letters A through Z, numerals 0 to 9, and special characters (i.e. $ # @ ! ^ ( ) { } ‘ ~ _ -) • A name cannot use the following: ASCII codes used as commands, space, special characters (i.e. + = / [ ] “ : ; ? * \ < > | )

Many software manufacturers use certain extensions for special file formats created by their application. DOS file names also have extensions. Listed below are some conventional file name extensions and their use:

Table one: Common file name extensions Extension Description ARC Archive (compressed file) ASC ASCII ASM Assembly source file BAK Backup file BAT DOS C C source file COM Program file DAT Data file DLL Windows dynamic link library DOC Document file (used by many word processors) DRV Device driver file EXE Executable program file INF Information file PIF Program Information File TXT Text file ZIP Compressed file (PKZIP)

2 File Attributes DOS tracks each file on a disk through a directory entry. This entry maintains critical information about the file and where it is stored on disk. One of the pieces of information maintained in the directory entry is the field. Each characteristic stored in the file attribute field is called the file attribute. Table two lists the attributes and their purpose in DOS:

Table two File attributes and their description Attribute Description Archive When DOS writes to a file, it sets the archive attribute on. Hidden This file is bypassed by most DOS file management commands and does not appear in a directory listing. only This file can be accessed for information but cannot be erased or modified. Subdirectory This attribute identifies the entry as a directory rather than a standard file. System This file is a DOS . Volume This entry is the volume label for a disk. The entry does not identify an actual file.

You can view and modify most attributes using the ATTRIB command. The syntax of the ATTRIB command is:

ATTRIB [+R|-R] [+A|-A] [+S|-S] [+H|-H] filespec [/S]

To set the attribute use the plus (+) sign and to set the attribute off use the minus (-) sign. The R is to set the read only attribute, the A is to set the archive attribute, the S is to set the system attribute, and the H is to set the hidden attribute.

Directories DOS directories keep your files organized. Think of directories as a file folder that may contain may files. The is an important table created by the FORMAT command. DOS uses the directory as a kind of index system for finding files. A directory may contain files and other directories (called subdirectories). Typically, any installation of new programs will create directories. Also it is a good idea to organize your files in a . Imagine filing every single piece of paper in one folder…This would it difficult to locate files. Therefore, avoid falling into the trap of creating a flat file structure.

DOS uses a name expression to traverse to a specified file or group of files. A path name expression has three components: drive, directories, and files. The drive component identifies the disk drive used to store the files. The drive component is made up of three characters: the drive letter, followed by a (:) and a backslash (\). For example: C:\ DOS uses the backslash character to separate the directories within a path name expression. The directory component of the path name expression is a list of all the

3 directories that must be traversed to get to the last named directory or the file component. For example: C:\Windows\System\Games\SOL.EXE

DOS path name expressions cannot exceed 63 characters in length, including the backslash DOS adds internally.

DOS provides the internal (or MD) command to create directories. The syntax for the MD command is:

MD d:\path\

For example: MD e:\brief\games\oldgames

DOS naming rules allow a directory name to be up to 11 characters long. You can create a directory names stuff.old, but by convention, DOS users have agreed to keep directory names to eight characters or less. The MD command can only create one directory at a .

Use the CHDIR (or ) command to change from one directory to another. For example, to change directly to the root directory from any directory on the disk, issue the following command: CD \

DOS enables you to remove empty directories at the end of a directory branch in the directory with the (or RD) command. If a directory contains files or has anther directory branching form it, the RD command fails.

The DELTREE command enables you to delete directories that contain files – even complete branches of a directory tree. The syntax for DELTREE is:

DELTREE /Y d:path

The /Y parameter is optional. DOS normally displays the following message before deleting: Delete d:path and all its subdirectories? [Y/N]

If you use the /Y option, then this message will not be displayed.

DOS provides an external command – TREE – that lists all the directories of a disk as a tree structure. The TREE command syntax is:

TREE d:\path /F /A

The /F switch instructs TREE to display the files contained within directories as part of the visual tree. The /A switch instructs TREE to use printable characters instead of the line drawing characters normally used to indicate branching of directories.

4 Renaming Directories The command enables you to rename directories from the command line and also moves files from one directory to another. The syntax of the MOVE command is:

MOVE d:oldpath d:newpath

The MOVE command requires two path name expressions. The first specifies the directory you want to and/or rename. The second path name expression specifies the new name of the target directory or the name of a directory to be created as a result of the command’s actions. If the directory does not exist, MOVE prompts you to whether the directory should be created.

When you issue a DOS command, COMMAND.COM, the command interpreter, looks first to see whether the command is internal to DOS. If the command is not internal, DOS looks on the disk for a file name having the same name as the command.

In this regard, both external DOS commands and other executable files have equal status. Files having the extensions: .EXE, .COM, and .BAT are all considered by DOS to be executable program files. DOS simply looks for any executable file having the same name as the command line keyword. It then runs the first file it finds.

You have three ways to make sure DOS finds an external program file. You can do any of the following: • Log on to the disk and directory that contains the command. • Supply the path in the command line. • Establish a DOS search path to the command’s directory.

The PATH command places a path search string in the DOS environment. DOS uses the contents of this to determine where on the system it should look for program files.

Normally, the PATH command is included as a statement in the AUTOEXEC.BAT file, so it takes effect at boot time. Using the PATH command is not restricted to AUTOEXEC.BAT only. You can type a new search string (using the PATH command) at any DOS prompt. The PATH command is used the same way (i.e at the DOS prompt or the AUTOEXEC.BAT). For example,

PATH C:\; C:\DOS; D:\WINDOWS; D:\TEMP

In this example, based on the PATH setting; if you enter a command at the DOS prompt and COMMAND.COM does not recognize it as an internal DOS command, DOS always looks first in the current directory. If the file cannot be found there, DOS uses the PATH information to first search the root directory of drive C, then the DOS directory of C; then the WINDOWS directory of D; and finally the TEMP directory of D.

5 Notice in the PATH command that the search directories are separated by semicolons(;). Also, the order in which the directories are listed is the order in which they are searched.

Temporary Directory Many programs and some DOS operations use a directory as a temporary location to store scratch pad files. A scratch pad file is a file that is created as a buffer to store information temporarily before a permanent file is created.

Redirecting the output DOS offers two features to enable you to capture screen output in a more usable form. You can use the MORE command to capture screen output from other commands and present the screen one at a time, pausing for a keystroke as each screen is displayed. MORE is entered on the command line of another command using the pipe ( | ) symbol as the separator. For example,

TREE /F | MORE

This example captures the output of the TREE command and passes it to the MORE command. The MORE command breaks up the output into single screen portions. As each single screen is displayed, MORE waits for you to press a key before it displays the next screen.

You can also use the DOS redirection feature to capture long outputs to a file or send it directly to a printer using the output redirection symbol ( > ). For example,

TREE /F > viewtree.txt

In this example, the output of the TREE command is saved in a file called viewtree.txt. You can then use an editor to view the output of the TREE command. If your editor has problems displaying graphic characters, use the /A switch to get readable output.

Another example, TREE /F >PRN

In this example, the output of the TREE command is directed to the printer. Make sure the printer is on-line and ready before typing the command.

6