BASICS OF DOS John H. Ristroph, Ph.D., P.E. Engineering and Technology Management Program University of Louisiana at Lafayette

This paper explains basic DOS file management commands available through the DOS prompt of Windows 95 and later. It initially assumes that the files on disk C: are organized into directories, as illustrated in Figure 1.

Root

Dir1 Dir2 --- DirN

DirA FileD File1 FileA FileF FileB FileE File2 File2 FileG FileC --- FileM MileHi

Figure 1. Sample Files and Directories

Directories: A is a special file that contains information about other files, including their addresses or locations on the disk. The is the top level directory shown in Figure 1. It contains the addresses of the directories named Dir1, Dir2, ..., DirN and the files named File1, File2, ..., FileM, MileHi. The directories Dir1, Dir2, ..., DirN contain the addresses of still more directories and/or files. Two different files can have the same name if they are in different directories, such as File2 in the root directory and File2 in the Dir1 directory. Each directory is essentially a separate address book that keeps track of only its own files. Most DOS systems are set up so that the name of the directory is part of the prompt, so the user knows which directory the is currently using to find file addresses.

Changing Directories and Current Directories: To use addresses in the root directory, first “change” to it by entering the change directory command followed by a backslash: \ The Enter key must be pressed after every DOS command, so it is not shown here. After changing to the root directory, then the prompt for drive C: would be: C:\> By default, commands refer to files having addresses given by the “current directory” shown in the prompt. For example, the command C:\> more File2 will cause the contents of the File2 whose address is given by the root directory to be displayed one screen at a time. One way to see the contents of the File2 whose address is given by directory Dir1 is first to change to Dir1 and and then give the more command: C:\> cd Dir1

1 C:\Dir1> more File2 The root directory is now “above” the current directory (Dir1). One way to go to the directory "above" the current is: C:\Dir1> cd .. In this case, the root directory becomes current and the prompt becomes: C:\>

File Names: A file's complete or consists of all the information that DOS needs to find it: its drive letter, followed by any directory name separated by backslashes, and then the . For example, C:\Dir2\DirA\FileG is the fully qualified name of FileG. The part of the fully qualified name that precedes the file’s name is referred to as that file’s name. If the user is currently on drive C:, then C: is optional and does not need to be included in the path name. Using a file's fully qualified name permits its reference without first changing to its directory. For example, the user can be in the root directory and input C:\> more \Dir2\DirA\FileG to display FileG. Alternatively, the user can first change to the directory and then use more: C:\> cd \Dir2\DirA C:\Dir2\DirA> type File2

Filenames can have two parts, separated by a period, such as filename.ext. The first or primary name can be up to 8 alphanumeric characters (plus a few others, such as the underscore, dash, or dollar sign), and the extension can be up to 3 alphanumeric characters. Directories usually have only a primary name. In DOS, file names are not case sensitive, so FileA and filea refer to the same file. DOS abbreviates long Windows' names.

Wildcards: Some commands can be made to refer to more than one file by the use of wildcards. For example, the following commands make directory DirN the current directory and then erase all of its files: C:\Dir2\DirA> cd \DirN C:\DirN> erase *.* The erase command causes files to be erased, and an asterisk (*) stands for any primary name or extension. A question mark (?) stands for any one character. For example, suppose that the user is in the root directory. Then File? refers to files FileA, FileB, ..., and FileM, but not file MileHi. Similarly, ?ile? refers to all of the files but MileHi, since it has one more character than the others. However, ?ile* refers to all of the files in the root directory (excluding directories).

ASCII files: ASCII (American Standard Code for Information Interchange) files contain only characters normally used in typing. They do not contain special characters that are found in executable files, graphics images, or word processor files. The edit command of DOS can be used to prepare ASCII files, or files can be exported from word processors in ASCII format. Edit is mouse driven and has a Help button in its upper right corner that can be clicked.

Executable Files: Programs are stored in files with names that sometimes have the extensions .exe or .com, such as kermit.exe. Such files are called executable files. Execute a program by inputting the primary name of the executable file that contains it. If that file's directory is current, then only the primary name is needed; otherwise the path name must be

2 placed in front of the primary name. For example, a user in a directory PROGRAM that contains prog1.exe can input C:\PROGRAM> prog1 causes prog1 to execute. Batch files are ASCII files that contain several the names of several programs, one per line. Inputting the primary name of the batch file causes each one of those programs to execute, one after another. The execution of batch files or programs frequently can be stopped by pressing the Ctrl and C keys simultaneously (^C).

If the user is not in the executable file's directory, then giving its fully qualified name will cause it to execute. For example, a user in the root directory who does not wish to change to directory PROGRAM can input: C:\> \PROGRAM\prog1 Another way is to give special instructions to the computer using the path command. This command gives DOS a list of directories in which to search when it cannot find an executable file in its current directory. When a computer is up, it is usually given a list of directories to search by a file in the root directory named autoexec.bat, including the one that contains DOS commands.

Selected DOS Commands: Provide below is a brief list of fundamental DOS commands. Each command is illustrated with an example. Further details can be obtained by using the Help command of DOS (also described below).

^C (pressing the Ctrl and C keys simultaneously) can interrupt and stop the execution of many commands. cd\ changes to the root directory. cd\Dir2\DirA changes to any other directory, such as \Dir2\DirA. copy file1 file2 copies the contents of the first file and assigns the new file the second name. If a file already has the name file2, it is destroyed. Remember that fully qualified names must always be given for any file not in the current directory. copy file1 + file2 combines file1 and file2. The combined file is named file1, and file2 is not changed. In general, only ASCII files should be combined. dir lists the contents of a directory. dir /w provides an abbreviated listing of the contents of a directory across the screen. dir | sort pipes or sends the output from the dir command to the sort command, instead of the screen. The sort commands sorts the file names into ascending order before they are displayed. dir > EraseMe.txt redirects the output of dir to a file named EraseMe.txt, instead of sending it to the screen. This is similar to piping, except that the output goes to a file instead of another program. erase file1 removes file1 from the disk. find "abc" file1 searches for the three characters abc in file1. It is case sensitive unless instructed otherwise. The command find "abc" file1 > outfile

3 redirects the output of the find command from the screen and stores it in the file outfile, if that is desired. help provides a list of help topics. Click on the desired topic; and when through, click on the File menu at the top of the screen and then select Exit to leave the program. If the name of the command for help is wanted is known, then input help followed by the command name, for example help dir. md NewDir creates (or makes) the new directory named NewDir in the current directory. move file1 \Dir2 moves file1 from the current directory into directory Dir2. move file1 file100 renames file1 to file100. rd NewDir removes the directory NewDir, provided that it is in the current directory and has no files in it. more file1 displays the contents of file1 one screen at a time. Usually only ASCII files can be read this way. type file1 | more displays the contents of file1 one screen at a time. The next screen is displayed when the space bar is pressed. The vertical bar pipes or sends the output from the type command to the more command, instead of the screen. Then the more command displays it a screen at a time.

Last updated 9/29/00.

4