DOS Commands

The MS-DOS commands can also be classified as per their use and the commands are

Directory commands
DIR, MD or MKDIR, RD, TREE & PATH

File Management commands
COPY, XCOPY, DEL, RENAME & ATTRIB

General commands
TYPE, DATE, TIME & PROMPT

Disk Management commands
FORMAT, CHKDSK, LABEL, VOL

DOS utility commands
MOVE, DELTREE, SCANDISK & SETVER

DATE
This command (internal) permits us to enter or change the date known to the system. Whenever we create or add to a file, the date is recorded in the directory. Its syntax is
DATE [mm/dd/yy]

TIME
This command (internal) permits us to enter or change the time known to the system. Whenever we create or add to a file, the time is recorded in the directory. Its syntax is
TIME [hh:mm:[ss[.xx]]]

CLS 
This command clears the terminal screen. Its syntax is CLS

VOL
This command displays the disk volume label or volume ID of the specific drive, if it exists. Its syntax is
VOL [drive:]

If we don’t specify a drive letter, MS-DOS displays the volume label or the disk in the default drive. To display the volume label of drive C
C>VOL C:

Volume in drive C has no label Volume serial number is 1106-16DF

DIR 
This command lists the files and the sub directories in a directory except the hidden system files such as MSDOS.SYS and IO.SYS, even if present, its usage is
DIR [drive:][path][filename] [/P] [/W][:]  [/O[[:]sort order]] [/S]  or DIR [C:][filename.[ext]Where,
[drive:][path][filename] – Specifies drive, directory, and/or files to list.
/P      –   This command lists the directory page wise and pauses after each screen of information.
/W    –   This command lists the directory width wise and Uses wide list format.
/O     –    List by files in sorted order and the sort order is given as
N  By name (alphabetic)       S  By size (smallest first)
E  By extension (alphabetic)  D  By date & time (earliest first)
/S     –    Displays files in specified directory and all subdirectories.

The information provided in the directory listing includes the volume identification and the amount of free space on the disk. The display line in the each file includes its size in decimal bytes and the date and time the file was last written to. If the directory contains more files than will fit on one screen, /p and /w can be combined as
DIR [C:][filename.[ext][/p][/w]

Global characters: “?” and “*” are known as global characters. These characters are used in the file name and extension parameters. (A “?” mark in the filename or filename extension means that any character can occupy that position or any of the remaining position in the filename or extension
To display all the files having extension .BAK of drive C type
C>DIR *.BAK

COPY
Copies one or more files to another location, its usage is
COPY source  [+ source  [+…]] [destination [/V] [/Y | /-Y]Where,
Source        –  Specifies the file or files to be copied.
Destination –  Specifies the directory and/or filename for the new file(s).
/Y               –  Suppresses prompting to confirm we want to overwrite an existing destination file.
/-Y              –  Causes prompting to confirm we want to overwrite an existing destination file.

To append files, specify a single file for destination, but multiple files for source (using wildcards or file1+file2+file3 format). For e.g.
COPY ABC.IMP B:

  • If the original file is on the default drive and we don’t specify the second pathname, the copy command is not performed and MS-DOS displays the following message:

File cannot be copied onto itself: 0 file(s) copied.

  • If the second option is a filename only, MS-DOS copies the original file to one on the default drive and renames it with the specified filename. E.g. C>COPY VIP.IMP VVV.IMP

We can use the global characters? And * in the file name and in the extension of both the sources and the target files. E.g.

A>COPY *.* B:

Copies all type of files in the current directory from the default drive A to B.

REN (RENAME)

Renames a file/directory or files/directories, its usage is

RENAME [drive:][path][directoryname1 | filename1] [directoryname2 | filename2]

Note that we cannot specify a new drive or path for our destination.

A>REN B: MAIN.PRG TIME.PRG

Renames the file MAIN.PRG on drive B to TIME.PRG

DEL (DELETE)

This command deletes the files specified by the drive and path name. Its syntax is

DEL [drive:][path] filename [/P] –OR- ERASE [drive:][path]filename [/P] [drive:][path]filename   – Specifies the file(s) to delete. Specify multiple files by using wildcards.

/P –      Prompts for confirmation before deleting each file. A message “Are we sure (Y/N)?” is displayed to verify that we actually want to delete the file. Type Y (Yes) if we want to delete otherwise type N (No).

If we do not specify the drive name the current working drive is assumed i.e. the files will be deleted from the current working directory.

A> del C:\temp

We can’t delete files that are marked as read only. Don’t use DEL command to delete a sub-directory. We can use the global filename characters ‘?’ and ‘*’ in the filename and extension e.g.

B> DEL *.BAK

TYPE

This command displays the contents of a text file on the screen. Its usage is

TYPE [C:] filename [.ext] –OR- TYPE [drive:][path]filename

Using this command we can view text without modifying it. We can redirect the output to a file or the printer e.g. the following command prints the contents of the file JAY.COB to the printer.

C>TYPE JAY.COB >PRN or DIR>PRN

If we want to redirect the output top a file, use filename instead of PRN. Global filename characters are not allowed in the filename or extension. If we try to display a binary file, we may see strange characters on to screen, including bells, form feeds etc.

MKDIR

This command creates a subdirectory in the specified disk. Its usage is

MKDIR [C:] path Or MD [C:] path –OR- MKDIR [drive:]path –OR- MD [drive:]path

If we omit the drive letter of the disk, the default (current) drive is assumed.

Path specifies the path of subdirectory names, i.e. when we create directories with MKDIR, they always appear under our working directory unless we specify a different path with the MKDIR command. All characters, that are valid for file name, are valid for a directory name. For e.g.

MD\WS

Will create a subdirectory namely WS under the root directory of drive A. the following command creates the subdirectory PRG under the subdirectory WS.

A>MD\WS\PRG

If the current directory is WS the following command creates the subdirectory PRG under the subdirectory WS. We can create as many subdirectories as we wish, limited only by available disk space. But be sure that the maximum length of any single path from the root directory to the desired level is no more than 63 characters, including embedded backslashes. Two or more files or directory can have the same name as long as they are defined in separate directories.

CHDIR or CD

This command changes the DOS current directory. Its syntax is

CHDIR [C:] [path] –OR- CD [C:] [path] [C:] – specifies the disk drive whose current we want to change or display. If we don’t specify a

drive the default drive is assumed.

C>CD\

This command changes the current directory of the default drive to its root directory.

C>CD..

This puts us in parent directory of our working directory. If our working directory is C:\DOS\BASIC and we want to change our path to another directory such as C:\DOS\PCTOOLS type the following command and press enter

C>CD\DOS\PCTOOLS

RMDIR or RD

This command removes a sub-directory from the specified disk. Its usage is

RMDIR [C: [[path] –OR- RD [drive:]path

With the exception of “.” And “.” entries, the directory we want to remove must be empty i.e. before removing a directory that contains hidden files and sub-directory. The root directory, the working directory or the directory that contains hidden files can’t be removed. Suppose we want to remove a directory named C:\DOS\TEMP, first ensure that the directory is empty and then type the following command.

RD C:\DOS\TEMP

The last directory name in the path is the directory (i.e. TEMP) is removed.

FORMAT

This command formats the disk to the specified disk. Formatting analyses the entire disk for any defective tracks; and prepare the disk accept MS DOS files by initializing the directory, File Allocation Table, and system loader. We must use this command to format all new disks before MS can use them. Be careful before formatting any disk, particularly a fixed disk because formatting destroys all data on the disk. Its usage is

FORMAT drive: [/V[:label]] [/Q] [/4] [ /S]

/4 – Format a single sided or double-sided diskette in a high capacity disk drive. (1.2MB)

/Q – Performs a quick format.

/S – To copy the operating system files MSDOS.SYS, IO.SYS, COMMAND .COM

The first two files are hidden files, so we can’t see these two files in a directory of formatted disks. If the operating system is not on the default drive, format prompts to insert a system disk in the default drive or in drive A. If the default drive is non-removable, a message system transferred is displayed if the operating system files are successively copied onto the disks we are formatting. /V prompts for a volume label after the disks is formatted as

Enter volume label (11 characters, enter for none)?

A volume label identifies and can be up to 11 characters in length. The volume label cannot be used in place of file names as input to any of the DOS commands.

LABEL

This command (external) creates, changes or deletes the volume identification label on a disk. Its syntax is

[C:] [path] LABEL [C:] [volume label]

To create a volume label type the following command

LABEL b: PURCHASE 89   or we can type    LABEL B:

Then we are prompted

Volume in drive B has no label

Volume Label (11 characters, Enter, for none)?

Type PURCHASE 89 and press enter.

MORE

This is an external command that reads data from the standard input device, sends one screen of data to the standard input device, sends one screen of data to the standard output device and then pauses with the message

—MORE—

Its usage is

[C:] [path] MORE

[C:] [path] before MORE specifies the drive specifies and path contains the MORE command file. The MORE command will not work if the disk is full or write protected because to hold input information until it is displayed, the MORE command creates a temporary file on the disk. This command is useful for viewing long files, e.g. the following command displays the contents of the LONG.COB on the screen at a time.

TYPE ONG.COB|MORE

If screen is full, the message “—MORE— Press any key to see the next screen” appears.

TREE

This external command displays all the directory paths found on the specified drive and optionally lists the files in the root directory and each sub directory. Its syntax is

[C:] [path] TREE [C:] Also TREE D:/f

PATH

This command (internal) search specified directories for command or batch files that were not found by a search of a current directory. PATH only finds files that can be executed; such as .COM, .EXE and .BAT files, it won’t find files with any other extension. Its syntax is

[C:] [drive][path] [:drive] [path]…] or   PATH;

We may specify a list of drives and path names separated by semicolons so that when we enter a command that is not found in the current directory of the drive that was specified with the command, MS-DOS searches the named directories in the sequence we entered them. Note that the current directory is not changed.

To display the current path, type PATH without any parameter. To reset the search path to null (no extended search path), type PATH followed by a semicolon. This is the default when DOS is started.

C>PATH C: DOS

CHKDSK

The CHKDSK command checks a disk’s formatted size and available memory space. It also indicates the amount of disk space consumed by system files, data files, and bad sectors. DOS 5 also reports the volume serial number and information about the disks allocation units (clusters).

[C: Path] CHKDSK [File Spec][/F]

C: Path is the drive and path where the command file is located if it is not in the current directory or in a directory on the search path.

File Spec is an optional drive and path, including the filename and extension, of the file that is the object of the command. Wild cards are allowed.

/F allows us to make actual corrections on the disk.

PROMPT

The PROMPT command changes the systems prompt to whatever we like. It is useful for finding out which directory we are in, before we modify or delete any file. It can display the time, the date or a single message. Its syntax is

PROMPT string

String includes any sequence of normal ASCII characters and any number of $x special purpose entries. Possible values for $x are shown below

SymbolMeaning
$pCurrent directory of the default drive
$gthe > redirection character (greater than)
$dsystem date
$ tsystem time
$ vVersion number
$bthe | (pipe) character (The vertical bar)
$qThe = character

ATTRIB

This command can display or change file attributes. Each file has got some attributes, according to which commands are applicable to it. For example a file having enabled hidden attribute cannot be seen with DIR command. Its syntax is

ATTRIB [+R | -R] [+S | -S] [+H | -H] [[drive:][path]filename]

Where,

+   Sets an attribute,   –   Clears an attribute,   R   Read-only file attribute,   S   System file attribute,  H   Hidden file attribute.

XCOPY

This command copies files and directory trees to another location. Its syntax is

XCOPY source [destination] [/P] [/S [/E]] [/W]

Source             Specifies the file(s) to copy.

Destination      Specifies the location and/or name of new files.

/P                     Prompts us before creating each destination file.

/S                     Copies directories and subdirectories except empty ones.

/E                    Copies directories and subdirectories, including empty ones.

/W                  Prompts us to press a key before copying.

DELTREE

It deletes a directory and all the subdirectories and files in it. Its syntax is

DELTREE [/Y] [drive:]path [[drive:]path[…]]

Where,

/Y                 Suppresses prompting to confirm we want to delete the subdirectory.

[drive:]path   Specifies the name of the directory we want to delete.

Note: Use DELTREE cautiously. Every file and subdirectory within the specified directory will be deleted.

MOVE

This command is utilized for moving files and renames files and directories.

To move one or more files

MOVE [/Y | /-Y] [drive:][path]filename1[,…] destination

To rename a directory

MOVE [drive:][path]dirname1 dirname2

[drive:][path]filename1            Specifies the location and name of the file or files we want to move.

Destination                              Specifies the new location of the file. Destination

[drive:][path]dirname1            Specifies the directory we want to rename.

dirname2                                 Specifies the new name of the directory.

File Naming Rules
Using COPYCON to build a file

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?