MS-DOS
Detail Concept of DOS Commands
In this article we will study about DOS commands in detail. Generally DOS commands are categorized in two – internal and external.
Internal Commands
Internal commands are those which are automatically loaded in the memory when DOS is loaded. Actually internal commands are integral part of a file – COMMAND.COM, one of the three system files that are loaded into memory when DOS is loaded. Other two are IO.SYS and MSDOS.SYS, but unlike COMMAND.COM, these two system files are hidden files.
Internal commands are simple and are used for common jobs, such as copying, deleting and renaming, displaying a directory’s contents, making a new directory or changing the current directory and so on. Table-(a) shows a list of internal commands.
break |
ctty |
goto |
rem |
type |
call |
del |
if |
ren |
ver |
chcp |
dir |
md |
rd |
verify |
cd |
echo |
path |
set |
vol |
cls |
exit |
pause |
shift |
|
copy |
for |
prompt |
time |
|
Table (a)
External Commands
External commands are small programs and are used for relatively complex jobs, such as copying the entire diskette, formatting a disk, sorting text, comparing two files, joining two or more files and so on. If you want to use an external command then it must have a corresponding disk resident command file on a floppy disk or a hard disk. Basically any file name with an extension .exe, .com and .bat is considered an external file. That’s why you do not need to type their filename extension. Unfortunately if you have more than one external command with the same name, then firstly the file .com extension would run, next file having .exe would run and in last file having .bat extension.
Table-(b) shows a list of external commands.
append |
diskcomp |
find |
mode |
select |
assign |
diskcopy |
format |
more |
share |
attrib |
edit |
graphics |
|
sort |
backup |
edlin |
join |
recover |
sys |
chkdsk |
fastopen |
label |
replace |
tree |
comp |
fdisk |
mem |
restore |
xcopy |
Some of these commands are discussed in the following article.
Some Simple DOS Commands
In this section you will see some very simple DOS commands.
date Command – The date command is used to display or set the date. The date command is used as:
C:\>date
Current date is Wed 01-08-2003
Enter new date (mm-dd-yy):
If you want to change the current date then type new date and press Enter key; otherwise just press Enter key directly.
time Command – The time command is used to display or set the time. The time command is used as:
C:\>time
Current time is 4:09:54.98p
Enter new time:
If you want to change the current time then type new time and press Enter key; otherwise just press Enter key directly.
cls command – The cls command clears the contents of a screen and leaves only the system prompt and a cursor. The cls command is used as
C:\>cls
prompt Command – The prompt command is used to display the directory name or change the prompt to any text you want. For example, let you want to change the prompt to any text, say New Prompt?, you use the prompt command as:
C:\>prompt New Prompt?
New Prompt?
DOS continues with this new prompt (New Prompt?) until you change it again or reboot. If you want to get back the current drive and directory name along with the greater than sign, you use the prompt command again as:
C:\>prompt New Prompt?
New Prompt?prompt $P$G
C:\>
Here $P stands for current drive and directory and $G stands for greater than sign. You can also use $D and/or $T to display the current date and/or time respectively in the prompt.
ver command – The ver command is used to display the current DOS version number. The ver command is used as:
C:\> ver
path Command – The path command defines a search path for external executable files, including batch files. The path command is used as:
C:\>path [pathname [;pathname]….]
Here four dots indicate that you can repeat the ;pathname parameter as many times as you want, to add more directories to this command. Two more pathnames are separated by a semicolon. Be sure than each pathname specifies a complete, absolute pathname, including the drive. For example,
path c:\; c:\dos; c:\jdk1.2.2\bin; c:\jdk1.2.2\lib
sets a path so that when an external executable file is executed, it is searched first in the current directory, next in the root directory on drive C, then in c:\dos, c:\jdk1.2.2\bin and finally in c:\jdk1.2.2\lib. Here one should remember that each time the path command defines a search path, it completely replaces the former search path. Therefore if you want to add another directory to the current search path then include the complete current search path.
And if you use the path command as:
path;
then it clears the search path. After this, DOS looks for executable programs in current directory only. If you type just path with no parameter, path displays the current search path. Here one should remember that DOS does not check to make sure that the directories are legitimate. The path does not produce an error message if path is not valid.
If it can not find the program in the current directory or any valid directory on the search path, DOS displays following message:
Bad command or file name
This error message does not necessarily mean that the program file is not in your system. It means that DOS did not find it in the current search path. Unfortunately DOS would not look anywhere else. The search path created by path is assigned to an environment variable named path using the set command as:
C:\>set path= c:\; c:\dos; c:\jdk1.2.2\bin; c:\jdk1.2.2\lib
set Command – The set command sets or changes values of environment variables or displays current values. The set command is used as:
C:\>set [variable=[Sring]]
Here variable identifies the environment variable to be set and String specifies a new value for the variable. if String is omitted, the current value of the variable is cleared.
For example,
C:\>set temp=d:\temp
sets the value of temp to d:\temp. Now all temporary files are stored in the directory specified by temp variable. And
C:\>set temp=
clears the environment variable temp. In this case, the DOS stores temporary files in the root directory of the current drive.
Wildcards Characters in DOS
DOS provides two special characters, called as wildcards characters. First one is asterisk (*) and second one is question mark (?). These wildcards characters are very useful in DOS command lines because they give you flexibility when you are specifying paths and files.
The ? Wildcard Character – A question mark is a filename or filename extension means that any character can occupy that particular position. For example,
C:\>dir report?.doc
lists all filenames on the default drive that begin with the characters report and that have any character in the next position. Here are some examples of such files:
report1.doc
report4.doc
report$.doc
reportx.doc
The * Wildcard Character – An asterisk (*) used in a filename or filename extension means that any character can occupy that specific position or any of the remaining positions in the filename or extension. For example,
C:\>dir report*.doc
Lists all the directory entries on the default drive with filenames that begin with the characters report and that have an extension .doc. Here are some examples of such files:
report.doc
report14.doc
report$.doc
reportxa.doc
Notice that DOS ignores any filename characters that follow the asterisk wildcard, upto the period that separates the filename from its extension.
Managing Files and Directories In DOS
In this section you will study various commands that help you to manage files and directories on your system.
File Commands
You can use several DOS commands to manage files. in this section we will study some more common commands.
dir Command – The dir command is used to list the files in a directory. The dir command is used as:
C:\>dir [drive:][pathname]
The dir also lists the drive’s volume label and volume serial number. If you specify the drive name with the dir command, all entries in the default directory of the disk in the specified drive are listed. For example,
C:\>dir
Lists all the entries in the current working directory on the default drive. The dir command can also be used with following two switches:
- /p for selecting page mode, causing the directory display to pause once the screen is filled
- /w for selecting the wide display and causes DOS to display only filenames and not other information
Normally the dir command lists all files with their sizes in bytes and the time and date of last modification. Another main point to note is that you can also use wildcard characters with dir command. Thus, the following dir command
C:\>dir *.exe
lists all such files that have .exe extensions.
type Command – The type command is used to display the contents of a file on the screen or on the printer. The type command is used as:
C:\>type filename
Here filename is the name of the file whose contents is to be displayed. However if your file has several pages and you want to display its contents, pausing after each page, you would use the type command as:
C:\>type filename | more
Here the vertical bar is, which is placed after filename, is termed as pipe, as stated earlier and more is an external command, also referred as filter, which is used to display the contents of a file page by page. To also send the file contents to the printer, press Ctrl and d keys simultaneously. Once the printer has been selected, any message, which appears on the screen, will also be printed. Press Ctrl and d keys again to deselect the printing.
However you can also print the contents of a file directly on the printer by using output redirection symbol ‘>’ as:
C:\>type filename > lpt1
You will study about pipes & I/O redirection symbols in the subsequent section.
copy Command – The copy command is used to copy one or more files; concatenate files. The copy command is used as:
C:\>copy sourcefile targetfile
Here sourcefile is the name of file whose contents are to be copied and targetfile is the name of the targetted file where the contents are to copied. Note that sourcefile and targetfile may include the driver and directory name (where the file(s) to be copied is located). For example,
C:\>copy myfile yourfile
Copies the contents of myfile to yourfile. If yourfile already exists then its previous contents are overwritten by myfile. The copy command asks if you want to overwrite the target file. When DOS asks you if you want to overwrite an existing target file then you can enter Y to overwrite; otherwise N to preserve the file. On the other hand, if your files does not exist then DOS creates a new file for you and then contents are stored into it. Note that both files are in current directory. You can also copy one or more files from one drive to another. Now let us see some examples.
- C:\>copy C:report.txt A:
This command copies the file report.txt from drive C to the diskette in drive A.
- C:\>copy A:report.txt C:
This command copies the file report.txt from drive A to the current directory.
- C:\>copy A:report.txt C:\editor
This command copies the file report.txt from drive A in the directory editor in drive C.
Here the copied files have the same name as the source file. However you can also assign a new name to the copied file. For example,
C:\copy C:report.txt A:letter.txt
This will copy report.txt file from drive C to drive A with the filename letter.txt.
The copy command can also be used to copy several files in one stroke by using wildcard characters. For example,
C:\>copy C:report.* A:myreport.*
This will copy all such files that have report as filenames and having any extension to diskette in drive A with the filename myreport with the same extension as the report files. if you do not specify any drive then DOS assumes that you are referring to the root directory. For example,
C:\>copy report.txt A:
This command looks for report.txt in the root directory of driver C. another main point to note is that if source identifies multiple files (by using wildcard characters) but only one destination filename then DOS concatenates or combines all the source files in destination. For example,
C:\>copy report.* myreport.doc
This command concatenates all specified files whose filenames are report with any kind of extension to create (or overwrite) myreport.doc. However DOS also provides the facility of concatenating two or more files in one file using a special symbol ‘+’. For example,
C:\>copy report1.doc + report2.doc report3.doc
This command concatenates two files report1.doc and report2.doc in one file report3.doc. Consider another example,
C:\>copy report1.doc + report2.doc + report3.doc
This time, the copy command concatenates three files, report1.doc, report2.doc and report3.doc into one file report1.doc, if it exists. If report1.doc does not exist then report2.doc and report3.doc are concatenated into report2.doc. If neither report1.doc nor report2.doc exist then it copies report3.doc to itself as through concatenating.
xcopy Command – The xcopy command copies files and subdirectories. You will be surprised to know that xcopy is similar to the copy command to some extent. When copying multiple files, xcopy is considerably faster than copy. xcopy copes empty files but not system or hidden files. There are various switches that can be used with xcopy. Here are some more commonly used switches:
- /V for verifying each file as it is copied
- /-Y for confirming before copying files
- /S for copying directories and lower level subdirectories
For example,
C:\>xcopy A: C: /S
copies all files including subdirectories (and files therein) from the diskette in drive A to drive C with new subdirectories created under C:\ as needed to fold new files. All files (except system or hidden files) are copied.
del Command – The del command is used to erase a file from a disk. The del command is used as:
C:\>del [drive:] pathname
To delete a file report.doc from the disk in drive A, at the DOS command prompt you would use the following command:
C:\>del A: report.doc
However if you omit the drive name then it deletes the specified file from the default drive. Thus the following command:
C:\>del report.doc
deletes the file report.doc from the default drive. Note that the del command does not work if you type the word delete, but you can substitute the word erase in place of the del command, as:
C:\>erase report.doc
Another main point to note is that you can delete more than one file at a time using wildcard characters. Thus
C:\>del report.*
deletes all such files having filename report and their extensions do not matter. It means that it will delete report.doc, or report.txt, or report.c, etc. Like other commands, del command also provides the facility of using a switch \p that prompts you before a deletion actually takes place. The reason behind this is that once you have deleted a file from your disk, you can not recover it.
rename Command – The rename command is used to change the name of a file. The rename command is used as:
C:\>rename [drive:][path] oldfile newfile
Here oldfile is the old name and newfile is the new name. The rename command renames all files matching oldfile. For example,
C:\>rename report.doc payroll.doc
changes the name of report.doc to payroll.doc. You may also use wildcard characters in either filename option, but if you use them in newfile, it will not change the positions of the corresponding charactrer. Thus
C:\>rename *.doc *.txt
changes the extensions of all filenames ending in .doc to .txt. Note that the rename command can be abbreviated to ren. For example,
C:\>ren chapter1 part1
renames a file named chater1 (on the disk in default drive) to part1.
print Command – The print command is used to print a text file on a printer while you are processing other DOS commands. The print command is used as:
C:\>print [path] filename
The print command can be used only if you have an output device, such as a printer or a plotter, connected to one of your computer’s serial or parallel port.
For example,
C:\>print report.doc
prints the file report.doc on your printer. Like other DOS commands, print command offers some switches, such as
- /d:device for the specific device
- /b:size for buffer size
- /q:qsize for the number of files allowed in the print queue
- /t for deleting all files in the print queue
The /d, /b and /q switches are allowed only the first time you run the print command after starting DOS. For example,
C:\>print /d:lpt1
sets up the print queue for printing on LPT1. Note that if print command is used with no option, it displays the contents of the print queue on your screen without affecting the queue.
Directory Commands
Now we will study how to create, change, display and delete any directory.
mkdir Command – The mkdir command is used to create a subdirectory in your current working directory. The mkdir command is used as:
C:\>mkdir [drive:] path
Or
C:\>md [drive:] path
Here path includes the new directory name. If you do not specify the path then it creates a new directory in the current working directory. For example
C:\>mkdir user1
creates a new directory named user1 under current working directory. However you can also make any directories anywhere in the directory structure. When you create a new directory, DOS automatically creates the “.” and “..” entries in the new directory. The “.” indicates a link to the current directory and “..” indicates a link to its parent directory. A shorthand notation for the mkdir command is md.
chdir Command – The chdir command is used when you want to change from your current working directory to a different directory. The chdir command is used as:
C:\>chdir [path]
Or
C:\>cd [path]
A shorthand notation for the chdir command is cd. Thus either of the following commands will change your current working directory to the directory called Letters:
C:\>chdir \Letters
C:\>cd \Letters
You can also come directly to the root directory from anywhere by using the cd command as:
C:\>cd \
Similarly you can come to the parent directory of the current working directly as:
C:\>cd..
rmdir Command – The rmdir command is used to delete a directory by specifying its path from a multilevel directory structure. The rmdir command is used as:
C:\>rmdir [drive]path
A shorthand notation for the rmdir command is rd. The rmdir command deletes a directory only when it is empty, except the “.” & “..” symbols. Therefore it is necessary to delete its files & subdirectories before you remove a directory. For example, let you want to remove a directory name \letters, you would use the rmdir command as:
C:\>rmdir \letters
However if you are working in the same directory & try to remove it, you will receive the following error message:
Attempt to remove current directory-.
Note that you can not remove a directory that contains hidden files.
Disk Commands
In last we will see two most frequently used disk commands – format & diskcopy.
format Command – The format command is used to format the disk in the specified drive to accept DOS files. The format command is used as:
C:\>format drive:
While using format command, one should remember that it will destroy any previously existing data on a disk & ignores drive assignments created by the assign command. DOS also provides some switches, which format a disk in a special way. Here are some important ones:
- /1 for formatting a single side of the floppy disk
- /4 for formatting a 5.25 inch double sided floppy disk
- /8 for formatting 8 sectors per week
- /s for copying the operating system files listed in the file formats.tbl from the disk in the default drive to the newly formatted disk, which must be of 1.2megabytes or greater in size; otherwise it rejects the command
- /f:size for specifying the size of the diskette to format
For example,
C:\>format A: /s
Formats a floppy disk in drive A & copy the operating system to it. As you hit Enter key, your system should display:
Insert new diskette for drive A:
& press ENTER when ready …
After formatting is complete, DOS displays the following prompt:
Volume Label (11 characters, Enter for none)?
Type N to exit the format.
diskcopy Command – The diskcopy command is used to copy the contents of the floppy disk in the source drive to a formatted or unformatted floppy disk in the target drive. The diskcopy command is used as:
C:\>diskcopy [drive1:] [drive2:]
Here drive1 is the source drive & drive2 is the target drive. Here drive1 & drive2 may be the same. For example,
C:\>diskcopy A: B:
copies the disk in drive A to the disk in drive B. The diskcopy prompts you to insert both disks at appropriate times & press any key to begin copying. However if you omit the drive options, DOS prompts you for the drives. And unfortunately if the target is not formatted, diskcopy formats it with the same number of sides & sectors per track as the source disk. If you omit both options, DOS performs a single-drive copy operation on the default drive. If you omit the second option DOS uses the default drive as the target drive. For example, in the following comman
C:\>diskcopy A: A:
DOS first asks you to insert the source diskette (diskette to be copied) in the drive A & then to insert the target diskette. After completing the copy operation, the diskcopy prompts you with the following message:
Copy another diskette (Y/N)? _
If you type Y then it prompts you to insert the source & target disks & performs the next copy operation on the drives that you originally specified; otherwise type N to end the diskcopy process. Here one should remember that diskcopy command works only with floppy disks. You can not use diskcopy with a hard disk.