Showing posts with label dos-command. Show all posts
Showing posts with label dos-command. Show all posts

The FORMAT Command

To make a floppy or hard disk capable of storage, DOS creates tracks and sectors on a disk. This process of creating tracks and sectors on a disk is called formatting. To understand this concept better, assume that you have a long roll of blank paper. To make this roll of paper usable (for writing), it could be cut into pieces about a foot long, and then lines and page numbers could be put on every sheet. You could consider this to be the equivalent of formatting whereby the disk is made usable.

After formatting is complete, the disk is divided into tracks that are concentric circles. Tracks are further divided into portions called sectors. Data is stored on these sectors as magnetic patterns.

Each track and sector has a number. During formatting, DOS also checks for defective spots and displays the number of bad sectors on the screen.

Assume that you have bought a new floppy disk and want to copy some files from the C disk to this disk.

For this, you have to first format the diskette because a brand new diskette cannot be used for storing data. All new disks have to be formatted before data can be stored on them. However, some diskettes are pre-formatted by the manufacturer.

The command for formatting a floppy disk in the A drive is:

C> FORMAT A: <Enter>

After you issue this command, the following message appears:

C>FORMATA:

Insert new diskette for drive A:

And strike Enter when ready

At this point, you insert a blank, unformatted disk in drive A and press the <Enter> key to begin the format. When the format program has ended, the following message will be flashed on the screen:

Format another (Y/N)?

If you want to format another blank disk, you press Y (for yes) and insert another blank, unformatted disk in drive A. If you do not want to format another disk, you press N (for no) to end the format program.

Old disks that already contain data can also be formatted if data is not required and the disk is needed for usage. In this case, all the old data is lost after the formatting procedure is completed. This is usually done if an old disk has certain bad sectors and is needed for usage. The FORMAT command must be used with extreme caution. Any disk that you format will lose all the data that existed on it before the formatting operation.

It is very important that you specify the drive name while issuing this command. The proper syntax for this command is:

FORMAT<drive name>

Be careful when you use the FORMAT command and ensure that you enter the right drive name.

FORMAT is an external command. In order to execute this command, the DOS file FORMAT.COM must be present. In contrast, there will be no program file called DIR.COM to execute the DIR command.

F0RMAT.COM is usually available along with the DOS software.

If you wish to specify a volume label for your disk, you may do so with the FORMAT command. In this case, the N option may be used. A volume label helps in identifying the disk and can be up to 11 characters in length. The command to be issued to give a volume label to a floppy disk at the time of formatting is:

C>FORMAT A:/V <Enter>

Another option that can be used with the FORMAT command is /S. If you issue the command:

C:>FORMATA:/S <Enter>

The operating system files are transferred from the C disk to the A disk, and the disk will be formatted. Now this floppy disk can also be used to load DOS into the computer's memory. The system files cannot be copied using the COPY command. In order to use a floppy disk to load DOS, the disk has to be formatted using the/S option.

If the operating system software (DOS) is available on the hard disk, you are prompted to insert a DOS diskette in the A drive.

Displaying the Contents of a File - the TYPE Command

If a file PAYROLL.DAT exists in the current directory of your hard disk and you want to see its contents on the VDU, the command to do so is

C>TYPE PAYROLL.DAT <Enter>

You can also specify a path to DOS with the TYPE command. If the same file PAYROLL.DAT existed in the directory PAYMENT of the hard disk, the following command can be issued to display its contents:

C>TYPE C:\PAYMENT\PAYROLL.DAT <Enter>

If the file PAYROLL.DAT exists in the root directory of the A drive and you wished to display its contents, you have to specify the drive name before the file name. The command to do that is

C>TYPE A:PAYROLL.DAT <Enter>

Note: The Type command is useful for viewing text files.

Moving Files - the MOVE Command

The Move command allows you to move one or more files from one drive to another drive or from one directory to another directory. Assume that there is a file INTERNET.TXT under the directory INCOME on the hard disk that needs to be moved to a diskette. This can be done by issuing the following command:

C>MOVE C:\INCOME\INTERNET.TXT A: <Enter>

This command deletes the file physically from the hard disk and moves it to the target location.

Deleting Files - the DEL Command

You may discover that there are some files on the disk that you do not require anymore. Unwanted files occupy space on the disk. Therefore, it is desirable to remove such files. Assume that there is a file CON.BAK on the hard disk, which you do not require anymore and want to remove or delete. This can be done by issuing the following command:

C>DEL C:CON.BAK <Enter>

This command deletes the file CON.BAK from the hard disk. DOS does not, however, give any confirmation of deletion of this file. If you wish to delete a file from the A drive, you have to specify the drive A before the file name. For example:

C>DEL A:CONFIG.BAK <Enter>

You can also specify a path to DOS with the DEL command. If you wish to delete a file named LOCAL.3, which exists in the directory NETWORK on the C disk, the command you could give is

C>DEL C: \NETWORK\LOCAL.3 <Enter>

Renaming Files - the REN Command

Sometimes you may find that a name that you had given to a file initially is no longer suitable. If you wish to change the name, you need not copy it again under a different name. DOS allows the user to change the name of a file. This can be done by using the REN command. If you have a file named ZZZ.PIT and you now wish to rename it to LOAN.SUM, the command would be

C>REN ZZZ.PIT LOAN.SUM <Enter>

The file ZZZ.PIT will now exist under the name LOAN.SUM. Though the name has been changed, the contents of the file remain the same. A path can also be defined with the REN command. Let us assume that you wish to change the name of the file CALM that exists in the directory WEATHER on the C drive. The new name to be given is STORM. The command you could give

C>REN \WEATHER\CALM STORM <Enter>

BACKUP and RESTORE Utilities

BACKUP allows backing up of files from a hard disk to a floppy disk. In the event of a hard disk failure or accidental erasures, we can fall back upon the backed up data. It can also be used to backup from one floppy to another, even if they are of different types (different in size or capacity). BACKUP can copy files from within subdirectories as well.

BACKUP copies all source files into a single file, and maintains the list of file names in another file called the log file. If all the files cannot be stored on one disk, BACKUP requests for the next disk. The log file also stores the number of the backup disks on which the source files are stored.

The RESTORE utility helps you to restore files that have been backed up using the BACKUP utility. Files are transferred from a backup set to the location we specify.

While the earlier versions of BACKUP and RESTORE were command driven, the present day versions are menu driven and more of utilities than commands, and hence more user friendly.

Copying Files and Directories - the XCOPY Command

If you have a disk that contains files in subdirectories, and you want to copy the directories and subdirectories too, the XCOPY command should be used.

You could also use the COPY command globally, but this would copy the files of only the working directory and not subdirectories and its files.

The DISKCOPY command may also be used. However, the disadvantage is that it formats the disk, and copies the entire contents of one disk to another. You may, perhaps, not want to lose the existing contents of the target diskette. Also, you may not want to copy the entire contents of the source disk.

The XCOPY command has a major advantage over the other commands to copy files, because this command offers two special options. One of these options prompts you to specify the files that you wish to copy, and the other copies the directories and lower level directories. Besides, unlike DISKCOPY, XCOPY can be used to copy files from the hard disk too.

If you do not wish to copy every file on the disk, you may use the /P option with the XCOPY command.

For example, if you issue the command:

C>XCOPY C: \REPORT A:\REPORT /P <Enter>

DOS will prompt you with (Y/N), allowing you to confirm whether you want to copy each target file.

If you wish to copy the directories and lower level directories, DOS offers you another option with the XCOPY command. In this case you may use the /S option.

The command you could issue is:

C>XCOPY C:\REPORT A:\REPORT /S <Enter>

This command will copy the directory REPORT and all its subdirectories, unless they are empty.

If you do not specify /S with the XCOPY command, it works within a single directory.

Both the options can be specified in a single command. For example,

C>XCOPY C:\REPORT A:\REPORT /P/S <Enter>

You are advised to include the path and file name with the XCOPY command; XCOPY assumes that the operations are to be carried out in the currently active directory.

The program file XCOPY.EXE must exist in order to execute this command.

Copying the Contents of a Floppy Disk to Another - the DISKCOPY Command

If you want to copy the entire contents of one disk to another, you need to use the DISKCOPY command. This command copies the contents of the floppy disk in the source drive to the floppy disk in the destination drive. On a PC-XT with a single floppy drive, the same drive will have to be the source drive as well as the destination drive.

The command for copying the contents of one floppy disk to another is:

C>DISKCOPY A:A: <Enter>

This command copies the contents of the entire disk in drive A (source drive) to the disk in the destination drive, i.e. drive A. Here, drive A acts as the source drive as well as the destination drive.

When you issue the DISKCOPY command, the following message is displayed on the screen:

Insert SOURCE diskette in Drive A:
Press any key to continue...

DOS will wait for you to insert the source diskette and press any key, before continuing. After a while, the following message will be flashed on the screen:

Insert TARGET diskette in drive A:
Press any key to continue...

Here, you are prompted to remove the source disk and insert the target disk.

After the process of copying is completed, the display on the screen is

Copy complete
Do you wish to write another duplicate of this disk (Y/N) ?_

If you press Y, DOS will prompt you to insert another target diskette and another copy will be made. If you choose N, the display will change to C>.

The target diskette can be formatted or unformatted. If the target diskette is not formatted, DISKCOPY formats it. In case of a used floppy, the original contents are lost because DISKCOPY formats the disk before copying.

The DISKCCOPY command works only with floppy disks and cannot be used with the hard disk.

DISKCOPY is an external command. The file DISKCOPY.COM must exist in order to execute this command.

File Commands of DOS

DOS allows you to perform certain activities on the files on a disk, such as copying files, deleting them and renaming them. Let us take a closer look at the commands that instruct DOS to carry out these activities.

Copying Files - the COPY Command

If you have a file on the hard disk, you may want to copy it on to a diskette so that you can work with the same data on another machine. Or, you may want a copy of the data that is on a diskette onto the hard disk. Files can be copied from one disk to the other using the COPYcommand. This command also allows you to copy files to a different location on the same disk.

Copying a File to Another Drive under the Same Name

If you wish to copy the files on the hard disk to the diskette, which is in the A drive, the command is

C>COPY C:COMMAND.COM A:COMMAND.COM <Enter>

After the execution of this command, the file COMMAND.COM will exist on the diskette in the A drive, under the same name. After issuing the above command, the screen appears as follows:

C>COPY C:COMMAND.COM A:COMMAND.COM
1 File(s) copied
C>_

DOS displays the following message to indicate to you that the command has been executed:

1 File(s) copied

When using DOS commands, if the file names are not preceded by the drive name, they are assumed to refer to the active drive. Hence, if COMMAND.COM is on the C drive, which is currently active, referring to it as C:COMMAND.COM or COMMAND.COM means the same. But the files from the non-active drive must have the drive name preceding the file name.

If the name of the file is to remain unchanged, the file name need not be specified after the target drive (the drive to which the file is to be copied), which in the example illustrated, is the A drive.

Copying a File to Another Drive under a Different Name

You may want to make some changes in a particular file without losing the original file. If this is the case, you can copy the file on to another disk and work on the copy. You will probably want to give the copied file another name so that you can distinguish between the two files.

You can do this by specifying the new file name after the drive name.

For example, when you issue the command

C>COPY C:SAL.DAT A:SALARY.DAT <Enter>

the file SAL.DAT on the hard disk will be copied on to the diskette under a new name, SALARY.DAT. The contents of both the files will be the same after the file has been copied.

Copying a File as a New File in the Same Drive

Instead of making a copy of SAL.DAT on a diskette, you may want to make a copy on the hard disk itself. You can copy the file in the same drive by issuing the following command:

C>COPY SAL.DAT SALARY.DAT <Enter>

After the execution of this command, you will have the same file under two different names on the same disk.

Copying Files from One Directory to Another

Let us assume that you have created various files under the root directory. You later realize that some of these files are related to each other and you would rather put them together. Therefore, you make a directory to contain these related files. You will recall that issuing the MD command can do this, but this directory is not automatically going to contain the files that you wish to organize under it. However, you do not have to go through the long-drawn process of creating these files again under the new directory. DOS allows you to copy the files from the root directory to the new directory that you have created. For that matter, DOS allows you to copy files from any one directory to another.

Suppose you have a file named SAL.DAT (containing details of salaries of the employees) under the root directory. Since you have already created a new directory called EMPLOYEE and wish to copy the file SAL.DAT to the EMPLOYEE directory, you issue the following command to do that:

C>COPY C:\SAL.DAT C:\EMPLOYEE <Enter>

After issuing this command, the file SALDAT gets copied under the directory EMPLOYEE.

Similarly, you can copy files from one directory to another by specifying the path to DOS. Consider an example where a file NEWMAN.P exists under the directory ACTORS, which is under the directory FAMOUS on the C drive. If you want to copy it to drive A under the NAMES directory under the root, the command is

C>COPY \FAMOUS\ACTORS\NEWMAN.P A:\NAMES <Enter>

After this command is issued, the file NEWMAN.P will exist on the diskette under the NAMES directory.

File Commands of DOS

DOS allows you to perform certain activities on the files on a disk, such as copying files, deleting them and renaming them. Let us take a closer look at the commands that instruct DOS to carry out these activities.

Copying Files - the COPY Command

If you have a file on the hard disk, you may want to copy it on to a diskette so that you can work with the same data on another machine. Or, you may want a copy of the data that is on a diskette onto the hard disk. Files can be copied from one disk to the other using the COPY command. This command also allows you to copy files to a different location on the same disk.

Copying a File to Another Drive under the Same Name

If you wish to copy the files on the hard disk to the diskette, which is in the A drive, the command is

C>COPY C:COMMAND.COM A:COMMAND.COM <Enter>

After the execution of this command, the file COMMAND.COM will exist on the diskette in the A drive, under the same name. After issuing the above command, the screen appears as follows:

C>COPY C:COMMAND.COM A:COMMAND.COM
1 File(s) copied
C>_

DOS displays the following message to indicate to you that the command has been executed:

1 File(s) copied

When using DOS commands, if the file names are not preceded by the drive name, they are assumed to refer to the active drive. Hence, if C0MMAND.COM is on the C drive, which is currently active, referring to it as C:C0MMAND.C0M or C0MMAND.COM means the same. But the files from the non-active drive must have the drive name preceding the file name.

If the name of the file is to remain unchanged, the file name need not be specified after the target drive (the drive to which the file is to be copied), which in the example illustrated, is the A drive.

Copying a File to Another Drive under a Different Name

You may want to make some changes in a particular file without losing the original file. If this is the case, you can copy the file on to another disk and work on the copy. You will probably want to give the copied file another name so that you can distinguish between the two files.

You can do this by specifying the new file name after the drive name.

For example, when you issue the command

C>COPY C:SAL.DAT A:SALARY.DAT <Enter>

the file SAL.DAT on the hard disk will be copied on to the diskette under a new name, SALARY.DAT. The contents of both the files will be the same after the file has been copied.

Copying a File as a New File in the Same Drive

Instead of making a copy of SAL.DAT on a diskette, you may want to make a copy on the hard disk itself. You can copy the file in the same drive by issuing the following command:

C>COPY SAL.DAT SALARY.DAT <Enter>

After the execution of this command, you will have the same file under two different names on the same disk.

Copying Files from One Directory to Another

Let us assume that you have created various files under the root directory. You later realize that some of these files are related to each other and you would rather put them together. Therefore, you make a directory to contain these related files. You will recall that issuing the MD command can do this, but this directory is not automatically going to contain the files that you wish to organize under it. However, you do not have to go through the long-drawn process of creating these files again under the new directory. DOS allows you to copy the files from the root directory to the new directory that you have created. For that matter, DOS allows you to copy files from any one directory to another.

Suppose you have a file named SAL.DAT (containing details of salaries of the employees) under the root directory. Since you have already created a new directory called EMPLOYEE and wish to copy the file SAL.DAT to the EMPLOYEE directory, you issue the following command to do that:

C>COPY C:\SAL.DAT C:\EMPLOYEE <Enter>

After issuing this command, the file SALDAT gets copied under the directory EMPLOYEE.

Similarly, you can copy files from one directory to another by specifying the path to DOS. Consider an example where a file NEWMAN.P exists under the directory ACTORS, which is under the directory FAMOUS on the C drive. If you want to copy it to drive A under the NAMES directory under the root, the command is

C>COPY \FAMOUS\ACTORS\NEWMAN.P A:\NAMES <Enter>

After this command is issued, the file NEWMAN.P will exist on the diskette under the NAMES directory.

Changing Directories - the CD Command

Let us suppose that there are two directories in the root—LETTERS and INCOME. You have been working on the files under the directory LETTERS and now wish to work on the files in the directory INCOME. This means that you would have to change from the Letters directory to the Income directory and make the latter the active directory.

DOS allows you to change your directory by issuing the CD command. The command to make the INCOME directory active is

C>CD\INCOME <Enter>

where CDstands for Change Directory.

The command for getting back to the root directory is

C>CD\ <Enter>

The command for going to the parent directory is

C>CD.. <Enter>

So, if you are in the subdirectory PERSONAL (refer Figure 1.6), then the above command will take you to its parent directory, iie. the root directory.

If you want to see the name of the directory in which you are working, the command you give is:

C>CD <Enter>

Just typing CD will display the name of the active directory.

For example, if you are currently in the Income directory and you give the command to display the directory name, the screen appears as under

C>CD
C:\INCOME
C>_

This indicates that you are in the INCOME directory under the root directory.

Removing a Directory - the RD Command

If the files in a subdirectory are not required or have been removed, it may no longer be necessary to retain the directory. The RD command can be used to remove such a directory.

To remove the directory WASTE on the C drive under the root directory, the command to be used is

C>RD C:\WASTE <Enter>

If the directory to be removed is not in the currently active drive, then the drive name must be specified. A path can be specified with the RD command. If a directory OLDSALES exists under the SALES directory on C drive and has to be removed, the following command can be issued:

C>RD C:\SALES\OLDSALES <Enter>

Whenever you use the RD command, remember that it can only be used to remove directories that are empty and are not currently active.

Displaying Path of a Directory - the TREE Command

The TREE command is used to display the path of each directory, subdirectory and files. The TREE command is used as follows:

TREE C: <Enter>

This command displays the directories on drive C with ail its subdirectories. Similarly, to view the path of each directory, subdirectory and files on Drive A, the command is:

TREE A: <Enter>

If you want to view all the subdirectories of the directory EXPENSES, the TREE command can be used as:

TREE EXPENSE <Enter>

Making a Directory - the MD Command

You have identified the need for directories whereby files can be organized on a disk in a structured manner. If you want to bring together and store files pertaining to the employees of a firm and those pertaining to the stock of the firm separately, you can do so by creating subdirectories. Prior to the creation of directories all the files reside in one main directory, which is the root directory.

To bring together all the files pertaining to the employees, you can create a subdirectory called EMPLOYEE. The command to do this is:

C>MD EMPLOYEE <Enter>

where MD stands for Make Directory.

After this command has been issued, a subdirectory called EMLOYEE is created under the root directory.

Rules for naming a directory are the same as those for naming a file. Just as meaningful names are given to files, it is good practice to give meaningful names to directories. This is to enable you to identify directories easily.

Making a Directory on the A Drive

If you want to make a directory on the disk in drive A, you would have to activate the A drive by giving the following command:

C>A: <Enter>

This command makes the drive A active. Now you may issue the MD command and create a directory on the diskette in drive A. The command to create the directory EMPLOYEE on drive A is:

A>MD EMPLOYEE <Enter>

Directory Commands of DOS

Certain DOS commands facilitate the creation or removal of directories so that you can organize the hard disk or a diskette. They also allow moving from one directory to another and viewing the list of files on a disk, under the root directory as well as other directories. These commands are the directory commands of DOS.

Displaying a List of Files on the Disk - the DIR Command

As stated earlier, there may be many files on a disk. If you wish to know which files you have on a particular diskette or on the hard disk, you can ask DOS to display the list of files on the disk.

For example, if you wish to view the list of files on the hard disk, the command would be:

C>DIR C: <Enter>

C: signifies the C drive. Pressing the <Enter> key indicates the end of the command.

A sample execution of the DIR command is shown in Figure.

For the time, ignore the significance of the first three lines. Notice that from the fourth line onwards, each line has 5 columns. The columns are:

  1. Primary name
  2. Extension


  3. Hence, columns 1 and 2 give the complete file name. For example, C0MMAND.COM is a file name where COMMAND is the primary name and COM is the extension.

  4. Size of each file in bytes. Recall that one byte stores one character
  5. Date on which the file was either created or modified last
  6. Time at which the file was either created or modified last

A Sample DIR Display

A Sample DIR Display

If you wish to see the list of files on the diskette, i.e. in the A drive, the command will be:

C>DIR A: <Enter>

In the list of files shown in Figure, PERSONAL is a directory. <DIR> signifies a directory. Therefore, the root directory of the C drive contains, apart from various files, a directory named PERSONAL.

Let us assume the directory PERSONAL contains a subdirectory called ADDRESS. To view the contents of the subdirectory ADDRESS, the command will be:

C>DIR C:\PERSONAL\ADDRESS <Enter>

where \PERSONAL is the path to the subdirectory Address

Thus, you can specify path to DOS along with the DIR command. If you wish to see whether a file named MK_APTS exists under the subdirectory ADDRESS, you can issue the command:

C>DIR C:\PERSONAL\ADDRESS\MK_APTS<Enter>

If the file does not exist there, DOS will indicate to you that the file has not been found.

If the currently active directory is the subdirectory ADDRESS, then the entire path need not be defined to DOS. The following command would be sufficient:

C>DIR MK_APTS <Enter>

You can see that the currently active drive need not be specified either. However, if you wish to view directory contents in a drive or a directory other than the active one, the complete path must be defined to DOS. Otherwise, an error message will be displayed.

More on the DIR Command

If you have a large number of files on a disk and you issue the DIR command, the file names will scroll off the screen and only the last few names will be visible. In such cases, the DIR command that can be used is:

C>DIR C:/P <Enter>

This command lists the contents of the disk page-wise. Once the screen is full of file names, the following message will appear and the scrolling will stop.

Press any key to continue...

When a key is pressed, the next screen of file names will be displayed.

An alternative command that can be used if one wishes to view all the file names at the same time is:

C>DIR C:/W <Enter>

A Sample DIR/W Listing

A Sample DIR/W Listing

The DIR/W command lists the contents of the disk width-wise, i.e. five file names per line (refer Figure)

As is evident from the screen in Figure, details like the number of bytes occupied by each file, the date and the time of creation of each file are not displayed with the file names when the contents are listed width-wise.