Learning MS-DOS Basics - A Tutorial
- View the contents of a directory
- Change from one directory to another
- Create and delete directories
- Change from one drive to another
- Copy files
- Rename files
- Delete files
- Format a floppy disk
The Command Prompt
C:\>
This is called the command prompt or DOS prompt. The flashing underscore next to the command prompt is called the cursor. The cursor shows where the command you type will appear.
If your command prompt looks like the sample command prompt above, skip to the following section, "Typing a Command."
If your command prompt does not look like the example, type the following at the command prompt, and then press ENTER:
Typing a Command
- To type a command at the command prompt
- Type the following at the command prompt (you can type the command in either uppercase or lowercase letters): nul If you make a typing mistake, press the BACKSPACE key to erase the mistake, and then try again.
- Press ENTER. You must press ENTER after every command you type. The following message appears: Bad command or file name The "Bad command or file name" message appears when you type something that MS-DOS does not recognize. Because nul is not a valid MS-DOS command, MS-DOS displays the "Bad command or file name" message.
- Now, type the following command at the command prompt:
Viewing the Contents of a Directory
- To view the contents of a directory
- Type the following at the command prompt:
Volume in drive C is MS-DOS_6.22 Volume Serial Number is lE49-15E2 Directory of C:\ WINDOWS09-08-92 10:27p TEMP 05-15-92 12:09p CONFIG SYS 278 09-23-92 10:50a COMMAND COM 53014 09-18-92 6:00a WINA20 386 9349 11-11-91 5:00a DOS 09-02-92 4:23p AUTOEXEC BAT 290 09-23-92 10:54a 7 file(s) 62931 bytes 8732672 bytes free
- To make sure you have a directory named DOS
If you do not see a line in the directory list indicating that you have a directory named DOS, type the following at the command prompt:
If the name that appears in place of DIRNAME is not DOS, substitute the name that appears for DOS throughout this tutorial. For example, if the name that appears in place of DIRNAME is MSDOS, type msdos whenever you are instructed to type dos.
- To change from the root directory to the DOS directory
- Type the following at the command prompt:
Next, you will use the dir command to view a list of the files in the DOS directory.
- To view a list of the files in the DOS directory
- Type the following at the command prompt:
- To view the contents of a directory one screen at a time
- Type the following at the command prompt:
Another helpful switch you can use with the dir command is the /w switch. The /w switch indicates that MS-DOS should show a wide version of the directory list.
- To view the contents of a directory in wide format
- Type the following at the command prompt: dir /w The directory list appears, with the filenames listed in wide format. Note that only filenames are listed. No information about the files' size or date and time of creation appears.
- If the directory contains more files than will fit on one screen, you can combine the /p and /w switches as follows:
- To change to the root directory
- Type the following at the command prompt:
No matter which directory you are in, this command always returns you to the root directory of a drive. The root directory does not have a name. It is simply referred to by a backslash (\).
The command prompt should now look like the following:
- To create and change to a directory named FRUIT
- Type the following at the command prompt:
2. To confirm that you successfully created the FRUIT directory, type the following at the command prompt:
or
dir /p
- To create and work with a directory named GRAPES
- Type the following at the command prompt: md grapes You will not see the new GRAPES directory until you carry out the dir command in the next step.
- To confirm that you successfully created the GRAPES directory, type the following at the command prompt: dir A list similar to the following appears:
- To change to the GRAPES directory, type the following at the command prompt: cd grapes The command prompt should now look like the following: C:\FRUIT\GRAPES>
- To switch back to the FRUIT directory, type the following:
Volume in drive C is MS-DOS-6 Volume Serial Number is lE49-15E2 Directory of C:\FRUIT .Note that there are three entries in the FRUIT directory. One is the GRAPES directory that you just created. There are two other entries---one looks like a single period (.) and the other looks like a double period (..). These directory entries are important to MS-DOS, but you can ignore them. They appear in every directory and contain information relation to the directory structure. The GRAPES directory is a subdirectory of the FRUIT directory. A subdirectory is a directory within another directory. Subdirectories are useful if you want to further subdivide information.09-25-93 12:08p .. 09-25-93 12:08p GRAPES 09-25-93 12:10p 3 file(s) 0 bytes 11534336 bytes free
In this section, you will delete the GRAPES directory. Before you begin this section, make sure the command prompt looks like the following:
- To delete the GRAPES directory
- Type the following at the command prompt: rd grapes
- To confirm that you successfully deleted the GRAPES directory, type the following at the command prompt:
Note You cannot delete a directory if you are in it. Before you can delete a directory, you must make the directory that is one level higher the current directory. To do this, type cd.. at the command prompt.
So far, you have been working with drive C. You have other drives you can use to store information. For example, drive A is your first floppy disk drive. The files and directories on drive A are located on the floppy disk in the drive. (You might also have a drive B, which contains the files and directories stored on the floppy disk in that drive.)
Before you begin this section, make sure your command prompt looks like the following:
- To change to and view files on a different drive
- Type the following at the command prompt: a: Note that the command prompt changed to the following: A:\> This message may appear: Not ready reading drive A Abort, Retry, Fail? If you see this message, the disk may not be inserted properly. Place the disk label-side up in the disk drive, and make sure the disk clicks into the disk drive. Then, type r for Retry. If this message appears again, press F for Fail, and then type b: at the command prompt. If you no longer see this message, type b: instead of a: throughout the rest of the tutorial. There must be a floppy disk in the drive that you want to change to.
- To view a list of the files on the floppy disk in drive A, type the following at the command prompt: dir A list of the files on the disk appears.
- Change back to drive C by typing the following at the command prompt:
So far, all the commands you typed were carried out on the current drive and in the current directory. You can also carry out a command on a drive that isn't current. For example, you can view the files on a disk in drive A without switching to drive A by following this procedure.
- To view files on drive A when drive C is current
- Type the following at the command prompt:
The following procedure presents another example of using a parameter.
- To view the contents of the DOS directory on drive C
- Type the following at the command prompt:
The c:\dos parameter specifies that you want MS-DOS to display the contents of the DOS directory on drive C, even though your command prompt indicates that the FRUIT directory is current.
Copying Files
To copy a file, you will use the copy command. When you use the copy command, you must include two parameters. The first is the location and name of the file you want to copy, or the source. The second is the location to which you want to copy the file, or the destination. You separate the source and destination with a space. The copy command follows this pattern:
- Copying a Single File
Before you begin this section, make sure the command prompt looks like the following:
- Return to the root directory by typing the following at the command prompt: cd\ The command prompt should now look like the following: C:\> Change to the DOS directory by typing the following at the command prompt: cd dos The command prompt should now look like the following: C:\DOS>
- Make sure the file you are going to copy, EDIT.COM, is located in the DOS directory by using the dir command followed by a filename. To see if the EDIT.COM file is in the DOS directory, type the following at the command prompt: dir edit.com A list similar to the following appears: Volume in drive C is MS-DOS-6 Volume Serial Number is lE49-15E2 Directory of C:\DOS EDIT Com 413 03-25-93 5:00a 1 file(s) 413 bytes 11999232 bytes free This shows that the EDIT.COM file is located in the DOS directory. You just specified another parameter with the dir command, one that directs MS-DOS to list only the files that match the filename you specified in the command. Since only one file in the DOS directory can be named EDIT.COM, the directory list includes only that file.
- To copy the EDIT.COM file from the DOS directory to the FRUIT directory, type the following at the command prompt: copy c:\dos\edit.com c:\fruit The following message appears: 1 file(s) copied The command you just typed copied the file from its source to its destination. By specifying C:\DOS\EDIT.COM as the source, you indicated that MS-DOS would find the source file EDIT.COM on drive C in the DOS directory. By specifying C:\FRUIT as the destination, you indicated that MS-DOS should place the copy of EDIT.COM on drive C in the FRUIT directory.
- Next, you will copy the EDIT.HLP file to the FRUIT directory. To confirm that the EDIT.HLP file is in the DOS directory, type the following at the command prompt: dir edit.hlp
- To copy the EDIT.HLP file from the DOS directory to the FRUIT directory, type the following at the command prompt: copy edit.hlp \fruit The following message appears: 1 file(s) copied If you forgot to leave a space before typing fruit, the following message will appear: Access denied If this message appears, type the command again and leave a space before fruit.
- To confirm that you copied the files successfully, view the contents of the FRUIT directory by typing the following at the command prompt:
Note that you specified the source and destination in the two copy commands differently. In the command you typed in step 4, you specified the source file as C:\DOS\EDIT.COM and the destination directory as C:\FRUIT. Both C:\DOS\EDIT.COM and C:\FRUIT are called full paths because you specified the drive and directory where these files are located. Specifying the full path is the safest way to copy files, because you provide all the information about which file you want to copy and which directory you want to copy it to.
In the copy command you typed in step 6, you specified EDIT.HLP for the source file and FRUIT for the destination directory. These are relative paths. A relative path specifies only the difference between the current drive and directory and the destination of the files you are copying. The following illustration shows how the DOS directory and the FRUIT directory are related:

When you typed the second copy command, you specified the source filename as EDIT.HLP instead of C:\DOS\EDIT.HLP. This is because drive C is the current drive, so you did not have to repeat C: in the path. The DOS directory is the current directory, so you did not have to repeat DOS in the path. You had to specify only the filename.
For the destination directory, you specified the relative path as FRUIT instead of C:\FRUIT. Again, you did not need to specify drive C, because drive C is current. However, the FRUIT directory is not current. To access the FRUIT directory from the current directory, DOS, MS-DOS must first return to the root directory (), and then switch to the FRUIT directory, before copying the file to its new location. Therefore, you typed the path MS-DOS must take to switch between the current directory and the FRUIT directory, or \FRUIT.
Copying a Group of Files
In this section, you will use wildcards to copy a group of files from the DOS directory to the FRUIT directory. In a card game, a wildcard matches any card in the deck. In MS-DOS, the asterisk (*) wildcard matches any character in that position and all the other positions that follow it. If you want to copy a group of files with similar names, using wildcards is easier than copying each file individually.
In this section, you will first view a group of files by using wildcards, and then copy the files using wildcards. Before you begin this section, make sure your command prompt looks like the following:
- View all the files in the DOS directory that end with the extension TXT by typing the following at the command prompt: dir *.txt Note that there is a space before the asterisk (*), but not after it. This command directs MS-DOS to list all files and subdirectories in the current directory that end with the extension JXT. The asterisk matches the first character of the filename and all other characters that follow it, up to the period () that separates the name from the TXT extension. A list similar to the following appears: Volume in drive C is MS-DOS_6 Volume Serial Number is lE49-15E2 Directory of C:\DOS NETWORKS TXT 8369 11-11-93 5:00a OS2 TXT 4587 11-11-93 5:00a README TXT 10858 11-11-93 5:00a 3 file(s) 23814 bytes MS-DOS lists all the files that end with a TXT extension. The wildcard in your command specified that MS-DOS should ignore the very different beginnings of the files and focus only on the extensions. Next, you will copy all the files with a TXT extension to the FRUIT directory by using wildcards.
- To copy the files with a TXT extension to the FRUIT directory, type the following at the command prompt: copy *.txt \fruit This command copies all the files that have the TXT extension from the current directory (DOS) to the FRUIT directory.
- To confirm that you copied the files successfully, change to the FRUIT directory by typing the following at the command prompt: cd \fruit
- To view a list of all the files in the FRUIT directory, type the following at the command prompt:
A list similar to the following appears:
Volume Serial Number is lE49-15E2 Directory of C:\FRUIT
EDIT HLP 17898 11-11-93 5:00a
NETWORKS TXT 8369 11-11-93 5:00a
OS2 TXT 4587 11-11-93 5:00a
README TXT 10858 11-11-93 5:00a
Renaming Files
This section explains how to rename files. You may want to rename a file if the information in it changes or if you decide you prefer another name.
To rename a file, you will use the ren command. The ren command stands for "rename." When you use the ren command, you must include two parameters.
The first is the file you want to rename, and the second is the new name for the file. You separate the two names with a space. The ren command follows this pattern:
- Renaming a File
- To rename the README.TXT file to PEACH.TXT, type the following at the command prompt: ren readme.txt peach.txt
- To confirm that you renamed the file successfully, type the following at the command prompt:
Renaming a Group of Files
You also can use wildcards to rename a group of files. If you want to rename a group of files that have similar names, using wildcards is easier than renaming the files individually. In this section, you will rename a group of files by using wildcards.
Before beginning this section, make sure your command prompt looks like the following:
- To rename the files whose names begin with EDIT by using wildcards
- List the files in the FRUIT directory that begin with EDIT by typing the following at the command prompt: dir edit.* A list of the files in the FRUIT directory that begin with EDIT appears.
- To rename the files that begin with EDIT to the new name PEAR, type the following command: ren edit.* pear.* This command specifies that all the files that begin with EDIT should be renamed PEAR, but should keep their original extensions.
- To confirm that you renamed the files successfully, type the following at the command prompt:
You can also rename extensions this way. For example, suppose you want to indicate that a group of files ending with a TXT extension are old. You can use wildcards to rename the files so they have the extension OLD.
- To rename all the files in the current directory whose names end with the extension.TXT
- View a list of all the files in the current directory with the extension TXT by typing the following command: dir *.txt
- To rename all files in the current directory that end with the extension TXT to end with the extension OLD, type the following command: ren *.txt *.old
- To confirm that you renamed the files successfully, type the following at the command prompt:
This section explains how to delete, or remove, a file that you no longer want on your disk. If you don’t have very much disk space, deleting files you no longer use is essential.
To delete a file, you will use the del command. The del command stands for "delete."
- Deleting a File
- Delete the PEAR.COM file by typing the following at the command prompt: del pear.com
- Delete the PEAR.HLP file by typing the following at the command prompt: del pear.hlp
- To confirm that you deleted the files successfully, type the following at the command prompt:
- Deleting a Group of Files
Before you begin this section, make sure your command prompt looks like the following:
- View all files that end with the extension OLD by typing the following at the command prompt: dir *.old A list of all the files that end with the extension OLD appears. Make sure that these are the files you want to delete. When you are deleting files by using wildcards, this step is very important. It will prevent you from deleting files accidentally.
- Delete all files ending with OLD by typing the following at the command prompt:
Now that the FRUIT directory is empty, you can delete it by using the rd (remove directory) command that you learned to use in "Deleting a Directory" earlier in this chapter.
- To delete the FRUIT directory
- Return to the root directory by typing the following at the command prompt: cd \
- You can see the FRUIT directory in the directory list by typing the following at the command prompt: dir or dir /p
- Remove the FRUIT directory by typing the following at the command prompt: rd fruit
- To verify that the FRUIT directory has been removed, type the following at the command prompt:
When you purchase new floppy disks, you may be required to format them before you can use them. Practice formatting a floppy disk now.
Caution The data on the disk you format will be erased, so make sure you select a disk that does not contain information you may need later.
- To format a floppy disk
- Type the following at the command prompt: format a: This command specifies that you want to format the disk in drive A. When you press ENTER, the following message appears: Insert new diskette for drive A: and press ENTER when ready ...
- Insert the disk you want to format in drive A label-side up. Then close the drive door or make sure the disk clicks into the drive. When you are ready, press ENTER. The following message appears:
Saving UNFORMAT information
1213952 bytes available on disk
512 bytes in each allocation unit.
2371 allocation units available on disk.
Volume Serial Number is lE49-15E2 Format another (Y/N)?
This concludes the MS-DOS tutorial. During this tutorial, you learned how to:
- View the contents of a directory by using the dir command.
- Change directories by using the cd command.
- Create directories by using the md command.
- Delete directories by using the rd command. C
- Change drives by specifying the drive letter followed by a colon.
- Copy files by using the copy command.
- Rename files by using the ren command.
- Delete files by using the del command.
- Format a floppy disk by using the format command.
No comments:
Post a Comment