operating system - prince edward island · ms-dos lab manual 2 note to teachers: the labs in this...

26
Operating System Lab Manual for Cmp 621A 2nd Edition Department of Education Feb., 1997

Upload: duongkiet

Post on 06-May-2018

216 views

Category:

Documents


2 download

TRANSCRIPT

Operating System

Lab Manual for Cmp 621A 2nd Edition

Department of EducationFeb., 1997

MS-DOS Lab Manual 2

Note to teachers :

The labs in this manual offer a brief introduction to the operating system used by your school’scomputers. It is suggested that you discuss the following topics with your students before startingthe hands-on lab sessions in this manual:

1] The purpose and function of an operating system.2] The fact that there are different operating systems (e.g. DOS, OS2, Windows 95,

etc.). Review the different versions of DOS and the version currently in use at yourschool.

3] The six basic components DOS:- ROM BIOS- Boot Record- io.sys file- msdos.sys file- command.com file- external commands

For more information on what each of these do, refer to a DOS manual or to PeterGriesbauer’s Computer 621 Course Notes, 1994, page 8, the section entitled “HowDoes DOS Work.”

Note to teachers concerning this 2nd Edition Manual.

This Second Edition Dos Manual attempts to respond to some of the concerns expressed by theteachers about the DOS Manual for the 621 course.

1. The first and foremost concern was whether or not DOS should still be included in the621 course, given that it is becoming outdated as newer and more user-friendlyOperating Systems are now making an appearance. In response to this concern it is feltthat although DOS is becoming less evident in everyday computer use, it is still importantto teach students the basics of files and how they are managed or organized. If studentshave this basic knowledge they can easily grasp the concepts of file management as itpertains to the various software packages that they will be using. It is felt that the bestway to teach the basics is to continue to offer some instruction in the structure of DOSand the various commands that come with the program.

2. Of concern as well is the problem of security on the LANs when we give students accessto DOS. In an attempt to solve this problem all of the exercises in this lab manual areexecuted from the A: drive. Only in special and non-risk situations are there exerciseswhich require use of the c: drive or any of the drives on the network. Although this willnot completely alleviate the security risks, it should help to avoid the problems whicharise from the inadvertent mistakes that are made when exercises are executed on drivesother than a:.

One problem with this method, however, is that the students do not have the opportunity

MS-DOS Lab Manual 3

to see the utility of the various drives and file management as it pertains to the variousdrives. Perhaps teachers can compensate for what is lacking in this area of the DOSsection by placing more emphasis on this aspect of file management when they work inWordPerfect or another of the software packages included in this course.

3. Finally, teachers expressed a concern that the DOS Manual was not an actual lab manualwith the necessary exercises to practice the concepts. We have attempted in this revisionto make the manual more of a lab style instruction book. In general the commands thatwere included in the first edition are included again in this edition. However, theexercises carry through from one lab to the next so there is a progression in the manual. The students are presented with various commands and the opportunity to practice thesecommands. An attempt has also been made to build each lab on the previous labsinstructions.

In closing I would like to acknowledge the help of Marion Cutcliffe and Peter Griesbauer in there-writing of this manual. Their suggestions and expertise were a great addition to the structuringand re-working of the present document.

MS-DOS Lab Manual 4

DOS Lab #1 Introductory DOS Commands

Objectives:1] To introduce students to the basic DOS commands(programs).2] Students will learn the functions of these commands and practice using them.

The Disk Operating System (DOS) allows the user to communicate with the computer. Whenyou “Boot” the computer you load DOS, which in turn consists of a number of components, allof which enable the user to perform the various functions, such as printing, listing directories,managing files, etc. One of the major components DOS loads is called command.com of whichone function is to load into memory a collection of the most often used DOS commands. Forexample, one of these commands is “DIR” which displays the listing of files in the default(presently active) directory. If, however, all DOS commands would be incorporated intocommand.com it would be too large and take up too much memory. Consequently, no otherprograms (eg. Word Processor, Games, etc.) could be used. For this reason, DOS separated anumber of programs (commands) into individual units. These are referred to as “ExternalCommands” as opposed to those residing in command.com which are called “InternalCommands”. The External commands are the commands that are available only from the diskwhere they are located and can only be activated by directing the computer to their location andthen typing their name. The Internal commands can be activated at any time simply by typingtheir name.

All this information is not important for the school computers because they have been setupusing the PATH command (more on the PATH command later) which automatically directs thecomputer to the location where the External DOS commands are stored. This information isincluded here, however, for home use. If you use these commands on your computer at homeand the commands are not working properly then the reason is probably that you are using anExternal command and you have not properly directed the computer to the location where thesecommands are stored.

Place a disk in drive a: ofyour computer. Type��������������������and pressENTER.

Format

Before using a disk, either a floppy disk or a fixed disk, the disk must be formatted.Formatting the disk lays down a series of segments and tracks that the computeruses to locate files saved on the disk. If you have a disk which already containsfiles, formatting the disk will erase these files.

As a minimum the format command must tell the location of the disk to beformatted. For example, format a: will format the disk in drive a:.

BE VERY CAREFULL WHEN FORMATTING A DISK. YOU MUST DIRECTTHE FORMAT TO THE PROPER DRIVE. IN THE EXAMPLE TO THE LEFT,IF YOU MISTAKINGLY TYPE FORMAT C: INSTEAD OF FORMAT A: YOUWILL FORMAT THE DISK AT C: WHICH IS YOUR HARD DRIVE AND THUSYOU WILL LOOSE ALL FILES STORED THERE.

MS-DOS Lab Manual 5

Using the same disk thatyou formatted above nowtype���������������������� and hitENTER

Using the same disk againtype ���������������������� and hitENTER

Using the same disk againtype ��������������������������and hitENTER

Switches

Switches allow the user to select extra options when working with MS-DOScommands. The option tells the computer to do extra work or to handle things in acertain manner. Switchs vary from command to command.

Syntax: Format [drive:] /s Installs the DOS system files on your disk sothe disk can be used to boot the computer. Itshould be noted that this command may notwork on the network. If it does not work,simply format the disk with the /v switch.

Format [drive:] /v Allows the user to give the disk a name.

Format [drive:] /s /v Carries out the two above functions at thesame time.

Type � ������ �����and pressENTER

Dir

The Directory command allows the user to see the index of the disk. This permitsthe user to verify if there are files on the disk and if so what these files are. We willdeal with the Directory command in more detail in later lessons but for themoment it is handy to be able to see the index of the disk inorder to see the nameof our disk and the files which have been copied as a result of the /s switch if the /sswitch worked.

Syntax: Dir [drive:] Shows the index for the disk in the specified drive.

MS-DOS Lab Manual 6

At the c:\> prompt type ����and press ENTER

At the a:\> prompt type ����and press ENTER

Changing drives

When first started, the computer uses the drive on which it found DOS as thecurrent drive. This may not be the drive on which you would like to work. Tochange drives, type the drive letter on which you would like to work followed by acolon, and press ENTER.

Syntax: c:\>[drive:] Changes from the c: drive to the drive specified.

a:\>[drive:] Changes from the a: drive to the drive specified.

b:\>[drive:] Changes from the b: drive to the drive specified.

With a disk in drivea:, type ������������������Whenprompted for a label,enter your name andpress ENTER. Forexample, JIM.

Label

The Label command is used to put a label identifier on a disk. After formatting adisk a prompt will request you to place a label on a disk. The label may beentered, a person’s name is often used, or the ENTER key pressed if no label isneeded. In order to re-label or delete a label one need not reformat the disk. Byusing the Label command the “name” on the disk can be changed or deleted.

Syntax: Label Allows the user to label the disk on the current drive.

Label [drive:] Allows the user to label the disk in the specifieddrive.

MS-DOS Lab Manual 7

Type������������: and pressENTER to see if the labelis your name.

Type ��������and pressENTER.

Type��������and pressENTER.

Vol

The vol command is used to check to see what label has been placed on a disk.

Syntax: Vol Allows the user to see the name of the disk in thecurrent drive.

Vol [drive:] Allows the user to see the name of the disk in thespecified drive.

Ver

The ver command is used to determine which verison of MS-DOS is being run inthe computer. This is important to know as some DOS commands have beenreplaced in later versions of DOS, for example edlin , and new commands havebeen introduced in later versions. The command xcopy is not available is someearly DOS versions.

Syntax: Ver Displays the version of Dos that is currently running.

CLS

The cls command is used to clear the screen. This command is helpful as it willremove any distracting information that is present on the screen.

Syntax: Cls Clears the screen.

Type��� ��� ����and pressENTER. Notice that thecomputer gives a time andthen asks you to enter atime. If the time is correctpress ENTER. If the timeis not correct, enter thecorrect time in the formatHH.MM and press ENTER

Date and Time

The date and time commands can be used to set the clock in the computer. Theclock in a computer is not precise, it will not keep time accurately. You may alsowant to change the time in your computer when the clocks change for daylightsaving time. You may also need to change the date in your computer.

Syntax: Time Allows the user to see the time and to make changesif necessary.

MS-DOS Lab Manual 8

Type���������� and pressENTER. Notice that thecomputer gives a date andthen asks you to enter adate. If the date is correctpress ENTER. If the dateis not correct, enter thecorrect date in the formatMM-DD-YY and pressENTER. It is notnecessary to enter the dayof the week, the computercan determine that fromthe date that you enter.

Changing the date or time in your computer is easy, but there are a few things tokeep in mind. When entering the time, use the 24 hour clock, for example 2PMwould be 14:00. You may also find it easier to use a period (.) Instead of a colon(:), the computer will understand this. It is not necessary to enter seconds orfractions of a second. The date should be entered in the mm-dd-yy format. Themonth will be first, followed by the day, then the year. All information should beadded as two digits. If the date that you wish to enter is July 1, 1990 then enter 07-01-90.

Syntax: Date Allows the user to see the date and to make changesif necessary.

Type ������������������������������������ andpress ENTER. You will nolonger see a DOS prompt.Now type �� � �������� � ������ andpress ENTER. PressCTRL-Z to save the file.List the files on drive a: bytyping � ����� ���� and pressingENTER. If the file test.txtdid not appear, try again.

Copy con

The copy con command can be used to write small text files to a disk. The filename must be specified and it is also a good idea to specify the drive to where thefile is to be saved. After writing the text, CTRL-Z must be pressed to save the file.You have just created your first file. In the next exercise we will create severalfiles that we will be able to use in subsequent exercises to practice more DOScommands.

Syntax: copy con [drive]:[filename].[extension]Once you have typed the text type CTRL-Z to save the file.

This command will save a text file to the specified drive with thespecified name.

Filenames

MS-DOS Lab Manual 9

In using the copy con command we have encountered Filenames. Before we create any more files we shouldhave a look at naming files in DOS because DOS has certain restrictions when it comes to naming files and anyprogram that functions with DOS as its operating system must follow the same rules when naming files.

Here are the basics of naming files with DOS

- No two files can have the same name. This applies only to files which are in the same directory of thesame disk. (More on directories later)

- The file name is actually divided into two sections. The “filename” and the “extension”.- The filename can consist of anywhere from 1to 8 characters in length. You cannot have spaces in your

name nor can you have any other of the characters which are used as separators in a DOS command. The name can be in upper or lower case although DOS will change all the characters to upper case.

- The extension is used quite often to identify a file as belonging to a certain group of documents orprograms. For example, all your Wordprocessing files could all be given the extension DOC. Thiswould tell you that the file is a Wordprocessing file.The extension consists of 1 to 3 characters. Thesame rules, in terms of characters which can be used, apply to the extension as applied to the filename. The extension is optional and, if used, must be separated from the filename by a period. If the extensionis not used do not include the period.

Here are some examples of proper filenames:

file1 test-1.his

file2.tst project2.m

1234 proj1020.doc - this is an example of the maximum length that a file name can have.

z 32

Now that we know how file names work use the������� command to create the following Text Files on drive a:. We will use these files later to practice copying, deleting, moving etc.

FILENAME CONTENTS

Test1.txt......................................................................Is your computer working?Test2.txt.....................................................................My computer is too slow.Note1.txt....................................................................This is a note to remind me of dinner.Note2.txt....................................................................This is a note to remind me that dinner is canceled.Letter1.doc.................................................................A letter to my Aunt Jeanne. Hi Aunty.Letter2.doc.................................................................A letter to my Uncle Sam.Notice1.rem..................................................................A bill that I have to pay.Notice2.rem..................................................................They repossessed my car.

Command summary and syntax for lab #1.

MS-DOS Lab Manual 10

Format command: format [drive:]Switches: command [drive:] /switch Directory command: dir [drive:]Changing drives: At the prompt type the new drive letter + :Label command: label [drive:]Volume command: vol [drive:]Version command: verClear screen command: clsDate command: dateTime command: timeCopy con command: copy con [drive:] filename.[extension]

MS-DOS Lab Manual 10

DOS LAB #2 Subdirectories

Objectives: 1] To become familiar with the different commands dealing with subdirectories. 2] To be able to organize and structure documents and files. 3] To be able to graphically display the structure of a directory.

Up to this point we have learned a few of the basic DOS commands and we have also created severalfiles and stored them on the disk in drive a: We are now going to create separate areas on the disk in a: so thatwe can copy individual files into individual areas. This will help us to organize our files.

Try each of the examples tothe right. Notice whathappens to the “prompt”each time. Make sure thatyou leave your prompt atthe last setting. (Setting #9)

PromptBefore we can start with this process we should have a look at the Prompt command.It facilitates file management in DOS.

This command allows you to display any text you want including information such asthe name of the current directory, the time , the date and the MS-DOS version number.

Syntax: Prompt [promptstring]

Examples: 1) PROMPT $Q = (equal sign) 2) PROMPT $$ $ (dollar sign) 3) PROMPT $T Current time 4) PROMPT $D Current date 5) PROMPT $P Current drive and path 6) PROMPT $V MS-DOS version number 7) PROMPT $N Current drive 8) PROMPT CALL PETER (Call Peter)

9) PROMPT $P$G Current drive, directory and Path

For each prompt example you get a different result or prompt. This can be useful ifyou want to leave a message to the person using the computer or if you want to leavethe time or the date as the prompt. Also, depending on the prompt that you choose,information such as your current drive, directory and path will be indicated. This isa useful prompt when we are doing file management and it is for this reason that wewill leave our prompt as is with the last example.

Make Directory

This command is used to create a directory. Md is followed by a space then the nameof the new directory. (The rules for naming a directory are the same as those whichapply to file names). This directory will be created as a subdirectory of the currentdirectory unless a full pathname is specified.

MS-DOS Lab Manual 11

Using the ���� commandcreate the followingdirectories on your disk indrive a:

����������������������������������������������������

Use the����������command to seeyour directories.

Syntax: mkdir [drive:][path]name

Or

md [drive:][path]name

Use ���� to change to the ��������

directory on the disk indrive a: Notice that theprompt now indicates thatyou are in this directory.

Use��� ��� to return to the rootdirectory.

Use ������to go to the ������������

directory.

Use cd\reminder to godirectly to the����������������

directory.

Change Directory

This command is used to move from one directory to another or to tell you whichdirectory you are currently working in. The Cd command by itself shows the currentdirectory of the current drive. To change to another directory, type cd leave a spaceand then type the name of the directory you would like to change to.

Syntax: cd [drive:][path]cd..

Below are a few examples of the way that the cd command can be used to navigatein directories.

Examples: 1) CD\ Returns you to the root directory 2) CD.. Moves you one level up in the directory

3) CD\ dos Moves you into the DOS directory4) CD\windows\system Moves you to the windows system directory

Use����������to return to the rootdirectory.

Use the ������command toremove the directory called��������.

Use�������� to see that thisdirectory has actually beenremoved.

Use the ������command tocreate the���������� directoryonce again.

Use�������� to verify that it hasactually been recreated.

Remove Directory

This command is used to delete a directory. To use the Rd command successfullyyou must a)remove all files from the directory which is being removed b) not be inthe directory which is being removed when you type the remove command.

Syntax rd [drive:][path]name

MS-DOS Lab Manual 12

Copy the file called����� �������� ��� from the root of a:to the subdirectory ��������

Hint: ������������ ����������������������� �����������

Change to the �������� directoryusing the ���� command andthen use the ������ command toverify that the file wascopied.

Copy the other three� ���� ���

files from the root of the a:drive to the subdirectory��������

Use the ���� command andthe ������ command tonavigate from one directoryto another and to verify thatthe files have been copied tothe correct locations.

Copy

The copy command is used to copy files from one location on a disk to another oreven from one disk to another. An example of the copy command is shown:

Syntax: copy [drive:][path]filename [drive:][path]

Example copy a:document.doc a:\business

The above command would make a copy of the file called document.doc found in theroot of drive a: and put this copy in the subdirectory called business

Using Wildcards copy all ofthe files with the extension������ from the �������������������� to thesubdirectory ��������.

Hint: �������� ������������������� �����������

Using Wildcards copy all ofthe files starting with thename ������������ and having anyextension. Copy these filesfrom the���������������������� to thesubdirectory ������ ������

Using Wildcards copy allfiles with a name startingwith ������ and any extension. Copy these files to thesubdirectory called ��������������

Wildcards

Copying files using the above method can become time consuming if we have to copyeach file one at a time. Using DOS wildcards allows us to copy files in groups. Thewildcards are the (*) and the (?). The (*) represents one or more characters and the(?) represents 1 character.

Syntax: The same as for the regular copy command

Examples: copy a:*.doc a:\personal Copies all of the files with the extension docin the root of a: to the subdirectory called personal.

copy a:test1.* a:\personal Copies all of the files with the name test1 andany extension to the subdirectory personal.

MS-DOS Lab Manual 13

Once the above commandshave been carried out all ofthe files that exist in theroot of a: should now alsoexist in their own separatedirectories.

Use the ������ command andthe ���� command to navigatethrough the directories andverify that all of the fileshave indeed been copied tothe appropriate directories.

copy a:tes*.* a:\personal Copies all of the files with a name that startswith tes and containing any extension. This file is copied to thesubdirectory called personal.

copy a:t?st*.* a:\personal Copies all of the files starting with the namet(any letter)st and containing any extension. This file will be copied to thedirectory called personal.

copy a:*.* a:\personal Copies all of the files in the root of a: to thesubdirectory personal. As you can imagine, this combination of wildcardsis used extensively with the copy command as well as several othercommands.

These are only a few of the possibilities which exist using the wildcards. Throughexperimentation you will become more familiar with their use. The wildcards can beused not only with the Copy command but with the following commands as well: Del;Dir; Ren; Xcopy; (We have not seen all of these commands as yet but will do so insubsequent lessons).

We have copied all of thefiles in the root of a: toseparate directories so nowto make extra room on thedisk we will delete the filesin the root of a:

Using the delete commanddelete the file called ����� �������� ���

from the root of a:

Use the ������ to verify that thedeletion has worked.

Using the delete command subdirectory called accounts on the disk in drive a:and Wildcards, delete allthe files with the extension������. Delete these files fromthe root of a:

Using the delete commandand Wildcards, delete allremaining files in the rootof a:

For all of the abovecommands use ������ to verify.

Delete

The del command is used to erase files from a disk. This command should be used withcare as you may accidently erase files that you wanted to keep. The command mustspecify the file name and it is also a good idea to specify the drive.

Syntax: del [drive:]filename

examples: del a:quest.doc Deletes the file called quest.doc from the root of a:

del a:\accounts\file1.doc Deletes the file called file1.doc from the

del a:*.doc Deletes all of the files in the root of a: with the extension doc.

del a:*.* Deletes all of the files in the root of a: BE VERY CAREFULWITH THIS COMBINATION OF WILDCARDS AND THE DELETECOMMAND. IT WILL DELETE ALL THE FILES IN THE CHOSENLOCATION. WHEN YOU USE THIS COMMAND DOS ASKS “AREYOU SURE”. YOU MUST RESPOND Y (YES) OR N (NO) AND THENPRESS ENTER.

MS-DOS Lab Manual 14

Command summary and syntax for lab #2

Prompt: promptMake Directory md [drive:][path]nameChange Directory cd [path]Remove Directory rd [path]Copy Command copy [drive:][path]filename [drive:][path]WildcardsDelete del [drive:][path]filename

MS-DOS Lab Manual 15

DOS LAB # 3 Other Important Dos Commands

Objectives: 1. To learn how to use the tree command.2. To learn how to use the Chkdsk command.3. To learn to use the TYPE and EDIT commands.4. To learn to use the RENAME command.5. To learn to use the DOS Key command.6. Extra Switches7. To learn how to use the MORE filter with the Pipe symbol.8. More switches with basic commands.9. To learn how to use redirectional signs.

Type ����������������Notice that allof the subdirectories aredisplayed

Tree

The TREE Command is used to graphically display the structure of a directory.

Syntax: tree [drive:] [path] -> the name of the directory where the tree shouldbegin.

Examples: 1) TREE (Gives the structure of the default directory.) 2) TREE b: (Gives the structure of the disk in the B: drive from

another directory.) 3) TREE c:\accounts Gives the directory tree for the subdirectory

call accounts on the disk in drive c:4) TREE /F (Gives the names of the files in each directory along

with the directory names.)

Type ������������ ������������� � Noticehow there are more thanone screen to the tree butthe pipe character allowsus to stop the screen fromscrolling until we hitanother key.

The Pipe character (|) (found on the backslash key on the keyboard):It is used inconjunction with such filter programs as the MORE command (which would pause theoutput after filling up one screen).

Example: TREE | MORE

MS-DOS Lab Manual 16

Type�������������������� and pressenter. Notice theinformation that isdisplayed.

Note: If you use the /fswitch DOS versions 6 andhigher will suggest thatScandisk be used. It is amore sophisticatedprogram than Checkdisk. Which one you run is yourchoice

Check Disk

This command is used to check the status of your disk and to fix disk errors.

Syntax: CHKDSK [(drive:)(path)filename]

Examples: 1) CHKDSK -> Used to display the status of the disk in thecurrent drive.

2) CHKDSK B: -> Specifies the drive that contains the disk thatyou want to check.

3) CHKDSK /F -> Fixes errors on the disk. Do not use thiscommand from Windows.

4) CHKDSK /V -> Displays the name of each file in everydrectory as the disk is checked

Type ��������

����������������� �������������������� ���The contents of this fileshould now be displayed.You will remember that youcreated this file previouslywith the copy.concommand.

Type

The TYPE command allows you to view the contents of anASCII file. An ASCII file is one that contains only the charactersyou see on the keyboard. This command can be useful when we want to see thecontents of a file that we created. The files that we created using Copy.con could befiles that we verify using Type. This file is used often to view the contents of theAutoexec.bat file used to boot your computer.

Syntax: type [drive:][path]filename

Type�������������������� ��������������������� ��� You will see a screen thatlooks like a simplewordprocessor. Add acouple of lines of text to thefile and then save this file.

Check the file with the ��������

command to see that thechanges have taken effect.

Edit

This command allows you to create text files as well as edit files that are alreadywritten. Note that the “Edit” command is only available in DOS 5.00 and laterversions. This command is like the copy con command although it is much morepowerful. Using this command you can edit ASCI files.

Syntax: edit [drive:][path]filename

Example: Type: EDIT reminder.txt (Enter) This creates the file Type: This is an example of (Enter) This creates the text Type: a text file created using (Enter) Type: MS-Dos 6's EDIT command. (Enter) Press: ALT, F, S to save the file Press: ALT, F, X to exit this text editor

MS-DOS Lab Manual 17

Type ���������������� ������������������� ���

����� �������� ���

Use ������ to verify that thechanges have taken effect

Rename

You may want to change the name of a file if the informationit contains changes, or if you simply decide to give it a better ordifferent name.To rename a file, use the REN command.

Syntax: ren [drive:][path]oldfilename newfilename

Change all of the filenamesin the Document directorywhich have the extension������ to filenames with theextension ������

Example: REN summary.doc report.txtExample2: REN c:\wperfect\item3.txt item3a.txt

If you want to rename several files at one time the wildcards work with the renamecommand

Example 1. REN letter.* report.*Example 2. REN *.doc *.let

Type ������������ at the promp As the doskey has only nowbeen installed, there will beno commands in the buffer.Let’s issue a fewcommands. Type thefollowing commands andpress ENTER after eachhas been typed:

dir a:verdir a:\documentvolcls

Now press F7. Whathappened? Press the uparrow key. Press it again.What happens? Press thedown arrow key. Press itagain.

Press the up arrow keytwice and then pressENTER.

Press the up arrow keyuntil the dir a: command isseen. Add ���������������� andpress ENTER. As you cansee, these commands can beedited.

Doskey

Doskey (Unfortunately, only available in DOS 5.00 or greater)The doskey command is a handy command to use when working from the DOSprompt. Before using doskey , it must be entered into the memory of the computer.To do this type doskey at the DOS prompt. Once Doskey has been entered into thememory of the computer it remembers all of the commands that have been enteredand these commands can be recalled to be reused or changed. This helps to avoidretyping commands which we use often.

Doskey can be used to find a history of the commands previously used while at theDOS prompt, or to recall commands one at a time. A list of the various doskeycommands is shown below:

Key Function

Up arrow Recall previous commandDown arrow Recall next command in listPgUp Recall top command in listPgDn Recall last command issuedF7 Lists all commands in the bufferALT-F7 Erases all commands in the bufferThere are other commands, but these will help in our course.

The doskey command and the keys associated with it make working at the DOSprompt an easier process. Instead of retyping commands, commands that have alreadybeen used are available for use again or for editing.

MS-DOS Lab Manual 18

Type ���������������������� and pressENTER. Press the ���� keyand when the last commandappears change �������� to������������ and pressENTER. As you can seethis function command canbe handy as a shortcut.

F3 function key

This key is similar to the Doskey command although it is not as elaborate a command.With this command you simply recall the last command that you typed at the prompt.This also can save you of retyping the command that you have just used and need again.

Type dir /?

Type dir c: /p

Type dir c: /w

Type dir c: /o

Try some of the otherswitches as well.

More about Switches

Switches are options which allow us to do more with certain commands. With acouple of the commands we have discussed thus far we have looked at switchesavailable with these commands. In the following section we are going to have a lookat a few commands which we have already discussed but with which we will now alsouse switches.

To discover which switches are available for a given command, typethe command followed by /?Example DIR /?

Some examples of DOS commands used with switches:

Example 1: DIR /P displays one screen of listing at a timeExample 2: DIR /W uses the full width of the screenExample 3: DIR /O displays a listing of directories first alphabetically - then a listing of files alphabetically. Example 4: DIR /O/P combining 2 switches in same commandExample 5: DIR /S displays a listing of all files in the present directory as well as in all sub- directories. This can be used to find a specific file. DIR WP.EXE /S

Example 6: COPY a:\project.txt c:\proj1.doc /v to verify the copy action to see that it was copied correctly. Example 7: DEL letter.doc /p to confirm that you really want to delete this file before actually doing it.

Example 8: Copy a:\*.* /y will prompt to confirm if you want to overwrite anexisting destination file.

MS-DOS Lab Manual 19

Command Summary and Syntax for Lab #3

Tree tree [drive:] [path]Check Disk chkdsk [[drive:][path]filename][/f]Type type [drive:][path]filenameEdit edit [drive:][path][filename]Rename ren [drive:][path]oldfilename newfilenameDoskeyF3 FunctionMore Switches

EXERCISES: (Presume A:\ > _ for each of the following).

Write the answers to the following in your notebook. Include with your answer thecommand or commands used to arrive at your answers.

1. Use the directory command and the change directory command to find out inwhich subdirectory the file letter2.doc is located.

2. What command would allow you to view the contents of the notice2.remfile?

3. Change the name of the letter1.doc file to letter.txt.

4. Delete all the files in the reminder directory that have the extension rem

5. What are the command(s) necessary to place all of the files in the root of a:into a directory called Mydir? This directory is not yet created.

6. Which command will give you a graphical representation of the directory structure of your hard drive....one screen at a time?

7. How do you get a wide directory?

8. How do you get a directory listing of all the files in all the subdirectoriesof your hard drive?

9. How do you get a listing of all the directories first (in alphabetical order),followed by a listing of all the files (in alphabetical order)?

10. What is the command used to verify problems on your disk. Which commandis recommended on later verions of DOS?

MS-DOS Lab Manual 21

DOS LAB #4 Batch FilesObjectives:

1] To become familiar with the purpose and functions of Batch files.2] To be able to write Batch files.3] To identify uses, applications, as well as limitations of Batch files.

On the disk in drive a: withall of the directories andfiles that you createdearlier, make a batch file tocreate a directory on drivea: called �������������� and thencopy all of the files in thesubdirectory ������������ intothe new directory calledletters. Call this batch file������ �������� �� To do this typethe following at the a:prompt

����������� ������������� ��

In the window that appearstype the following:

������������������������������������ ���������������������������� ������������

Go to the file menu andsave the file and then exitfrom the editor.

To run your batch file atthe a: prompt type ������������

You don’t need the batextension. Once you runthe file check the drive withthe DIR command to verifythat the file that youcreated actually workedproperly and all of the filesare in the proper place.

Congratulations, you havejust created your first batchfile.

A Batch file is a text or ASCII file that contains DOS (Batch) commands and isidentifiable as such by the extension: “BAT”. Batch files are used when you wish toexecute a frequently used set (batch) of DOS commands, with a few keystrokes.

Any command that is available in DOS is available for use in a Batch File. To createbatch files it is easiest to use the Edit command and include the name of the Batch filethat you want to create and also the .bat extension. This will create the named file andopen the edit window to allow you to enter the commands that you wish to includein your batch file.

An example of a simple batch file would be a file which gives the commandsnecessary to make a directory on your disk and then copy files to this directory.

The commands to enter would be the following:md funcopy *.gme a:\fun

This is a simple batch file that includes only two commands. It will create thedirectory called fun. This directory will be created as a subdirectory in the activedirectory. Once the sub-directory is created it will copy files with the extension .gmefrom the active directory to the subdirectory fun. Once you have entered the necessary commands into the file, save the file and exitfrom the edit window. To run your batch file, type the name of the file at the promptand type Enter. You do not have to include the extension in the name in order for thefile to run.

MS-DOS Lab Manual 22

In the above batch file itwould be nice to verify eachcommand as it is carriedout. We will add pauses tothe batch file to enable us todo that. Before we can dothat, however, we mustdelete the files in thedirectory �������������� and thendelete the directory ��������������. Then we can re-run thebatch file. Please do sonow. Once these files andthe directory are removedtype

����������� ������������� ��

When the file appears type�������� between the first andthe second line. Now type������ so that we can see thedirectory just created. Type �������� once again. Type �������� as well at theend of the file. Finally, itwould be nice, if we couldsee the index of the lettersdirectory that we justcreated so for the lastcommand type ����������������������������

Save your file, exit from theeditor and then run the fileto test it.

Notice that the computerwaits for you to strike anykey each time that youentered a pause in the batchfile.

Pause

Will cause a pause in the batch file execution and prompt the user with the message:“Press any key to continue...” This can be useful when you want to see what is goingon during the running of the batch file because it halts the execution. In conjunctionwith the Rem and Echo commands (the following commands) the Pause command canhelp us to manage the execution of batch files. This offers extra protection shouldsomething be going wrong. If there is a problem simply press CTRL + C and the batchfile will be terminated. You can then edit the file to correct the problem.

MS-DOS Lab Manual 23

Edit your batch file onceagain. This time at thebeginning of the file type�������������� �������������������������� ��������������������������������������������������������������������������������������������� ����������������� After thisline put in a �������� so thatyou have time to read theRem. Save the file with thechanges. Before you runthe file, however, youshould once again deletethe files in the lettersdirectory and then deletethe letters directory so thatthe batch file will runproperly.

REM or ;

Allows the programmer to place comments in the batch files. These are non-executable statements and serve only for clarification of the program

MS-DOS Lab Manual 24

Edit your batch file again. This time type Echo off atthe beginning of the file. Save it and run it. Don’tbother to delete the filesfrom the directory ��������������

nor should you delete thedirectory �������������� itself. However, when you run thebatch file you will get someerror messages because thebatch file is trying to createdirectories and files thatalready exist. Ignore theseproblems and run the fileanyway.

Using Echo off you havesuppressed the commands. All you see are the resultsof your commands.

Now edit the file again andreplace ���������������� at thebeginning with !���������!��������� Notice when you run thefile this time not even themessage echo off isdisplayed.

Edit the file once again andchange ������ to��������. Notice when you runthe batch file that thebeginning line is displayedbut there is no command infront of it this time. This ishandy when you want tocreate menu items on thescreen and all you wantdisplayed is the option oroptions with no other DOSmessages or commandsdisplayed.

ECHO:Enable/disable echo or display a message.

Examples: ECHO OFF All subsequent commands will not be shown ECHO This message will be shown @ECHO OFF will disable display of all commands including this one.

Parameters:

A parameter is the information that is passed on to variables within a batch file. Thesevariables take the form of %1, %2, %3,....%9. (More are available with the SHIFTcommand.) The parameter(s) must be passed at the command line.For example, consider the following batch file, named Back.bat, which has as itspurpose to make a copy of all files with the extension .wpd and to put these files inthe subdirectory called documents.

MS-DOS Lab Manual 25

We will now create thebatch file to the right. Tomake this file work youshould use the editor or thecopy.con command andcreate two or three fileswith the extension ��� ��� in theroot of the a: drive. Onceyou have created these filesat the a: prompt type ��������

��� �� ��� �� to open the Doseditor and create the emptybatch file.

Now type the following:

@Echo offmd filescopy *.fil a:\files

Save this program and thenrun it.

Let’s now edit the back.batand use variables. Beforewe do this create two orthree files in the root of a:with the extension ������

Type ����� ��� ������� ��� ��

Change the 2nd line from���������������� to ���"����"�

Change the 3rd line fromwhat it is to������� "#����"�������� "#����"�

This batch file will allowyou to specify, each timethat it is run, whatdirectory you will createand what file extension tocopy to that directory.

To run the file, type thename and then specify thevariables after the name

eg: a:\>back memos mem

Running our batch programin this fashion will create adirectory called memos andthen it will copy all of thefiles with the extensionmem from the root of a: tothe directory called memo.

Each time that you run the

@ECHO OFF disable display of all following commands

COPY *.wpd A:\document will copy all files from the default, with the extension“wpd” to the directory documents

The problem with this batch file is its restrictiveness, ie. you can only copy files withthe extension .wpd and you can only copy them to the subdirectory document.To lift the first restriction, we rewrite the second line of the above batch file with aparameter:

COPY *.%1 a:\document

will copy all files from the default, with the extension specified at thecommand line to the subdirectory documents.

Call

This command is used to “call” one batch program from another batch program.

example: call another.bat

This will run another.bat within the batch program that is presently running.

MS-DOS Lab Manual 26

The Autoexec.bat batch file.

A special Batch file is the Autoexec.bat file. This file contains instructions for thesystem to perform at start-up. DOS automatically looks for this program at startup andexecutes any of the commands found in this file. You can specify different things inyour autoexec.bat such as date and time and also what program you want to run atstartup.

The Path Command

A path is the course that leads from the root directory of a drive to the file you wantto use. The PATH Command enables you to tell MS-DOS to search in othersubdirectories for the programs you want to run. The best place to execute the PATHCommand is in the AUTOEXEC.BAT file so it will automatically be executed everytime you turn on your computer

Syntax: PATH [(drive\path;drive\path;...)]

Example:PATH C:\DOS;C:\WP51;C:\ADMAST

Note: Only the directories listed in the path will be searched. Do not use a spacein any path set or between path sets; only the semi-colon is allowed between sets.

Batch files to practice on

Write a batch file that will simulate the “move” command available in DOS 6.x. This command will copya specified file into a directory and then will delete that file from the source directory.

Write a batch file that will show you the files in a directory of your specification, then will wait until yousignal to continue by pressing any key, and finally it will show you the directory of another drive. You shouldallow for the possibility, that a directory may contain a large number of files and you may wish to stop thedisplay after each screen.Can you think where such batch file may be useful.

Write an “autoexec.bat” file, which contains all the commands which you may wish to activate at start-up. As a bare minimum, you should include the prompt and the path commands.

If time permits, write a menu.bat in which you allow users to select the application they wish to run froma menu. Hint: design a nice menu and call it menu.dat. Now write a batch file, that clears the screen and typesthe menu on the screen. After execution of this batch file, the user is returned to the DOS prompt. Now writethe necessary batch files to evoke the user’s choices. For example, if the user pressed the number “1" (eg. thefirst choice on your menu), it will run 1.bat, if the user selected “2" it will run 2.bat, etc. Of course, 1.batcontains the starting instructions for the application specified in number 1 of your menu. This batch file worksbest if you can launch your programs from the a: drive and when these programs are not dependant on windowsto run. In your file you can include such echo statements as “Put your program disk in drive a:”. Then use apause and then include the filename for the program that you want to run.