DOS primer
Courtesy of the alt.comp.virus newsgroup participants.
(These "anti-malware" pages are the result of a continuing cooperative effort.)
Translated versions available: in het Nederlands and Deutsch.
 Main Menu
Contributed by: Frederic Bonroy
The following text will hopefully help you understand basic concepts of MS-DOS and
how to work with it. The knowledge you will gain may be helpful if you ever need to
boot your computer from a clean floppy in order to remove a virus.
1. The command line
DOS is command-line driven. This means that there are no fancy icons and no mouse to click
on those icons; instead you have to tell the computer directly what you want it to do by
entering instructions at the prompt.
The prompt does of course not consist of random characters. It has a certain
structure and provides you with some useful information. Here is what it looks like
(in this case after you have booted from a clean floppy):
The letter "A" designates the current drive and is followed by a colon (":").
Drive A: corresponds to the floppy drive (just like under Windows). After that comes the
current directory (this is what a folder is called under DOS). In this case it's the root
directory which the \ stands for. The root directory is the topmost directory in the
directory hierarchy. Any other directory is just a subdirectory of the root directory.
The > sign terminates the prompt.
Note that DOS allows you to define the shape of the prompt (we won't discuss this here), but in most cases this is what it looks like.
The following is also a perfectly valid prompt. It shouldn't be too hard to guess which
directory we are in right now... it's the directory named TEST on drive A:
2. Entering instructions
As I said above, you tell the computer what to do by entering instructions at the prompt
and confirming by pressing the Enter key. The computer then analyses the instruction and
carries it out if it recognizes it. Suppose we enter something silly:
A:\>pizza
Bad command or file name
|
Obviously the "pizza" instruction is totally meaningless. But DOS is still
being helpful and tells you what is wrong. It says that you entered a "Bad
command or file name". This in turn reveals that DOS will accept both
"commands" and file names as "instructions".
But where is the difference?
3. Commands and file names
The program that displays the prompt and lets you enter instructions is called
the "command interpreter". It's the file command.com. A command
is basically an instruction which is executed by the command interpreter itself.
Entering a "good" file name (as opposed to a "bad" file name)
on the other hand, loads and launches the specified file. A "good" file name
is the name of a file that DOS knows to be executable (executable file extensions are .bat,
com and .exe)
4. The "dir" command
You are going to have to work with files, so of course it would be useful to know
what files there are in the directory. The command "dir" displays a list
of files in the current directory along with some supplementary information about
each file. Here is some sample output:
A:\>dir
Volume in drive A has no label.
Volume Serial Number is 1234-5678
Directory of A:\
TEST <DIR>
01-01-99 01:02
AUTOEXEC BAT 391 12-05-99 14:40
CONFIG SYS 63 12-05-99 14:45
HIMEM SYS 33,447 05-05-99 22:22
EMM386 EXE 126,695 05-05-99 22:22
COMMAND COM 96,370 05-05-99 22:22
5 file(s)
256,966 bytes
1 directories
1,200,698 bytes free
|
The first two lines starting with "Volume" are uninteresting. The third line reveals which directory dir is showing.
Then follows the content of the directory. TEST is a directory in the directory we are in; it's a "subdirectory". The "<DIR>"
indicates that.
Then follows a list of files. Each line consists of the
file name, its extension, its size in bytes and the date and time it was last modified.
The last two lines at the bottom show short statistics about the directory.
Note that if you let dir display a list of files and subdirectories of a directory
on your hard disk, you may encounter files or directories that look like this:
c:\progra~1
In fact, this is the "C:\Program files" folder. As opposed to Windows, DOS
does not allow files or directories names to be longer than 12 characters (including
the dot) or to contain spaces. Windows shortened the name somewhat so that DOS can
display it. Don't worry, Windows will still display it correctly as "C:\Program
files".
So DOS displays the first 6 characters of such a "long" file or directory
name. If they match the first 6 characters of another long file or directory name,
then DOS increases the number after the "~" by 1.
The "dir" command accepts certain parameters. Parameters define how the
command should behave. If, for example, there are more files in the directory than
displayable lines on the screen, the screen will scroll very quickly and you will see
only the files at the bottom of the list. To avoid this, you can specify the parameter
"/p" which tells dir to stop after it has filled a screen. It will wait
for you to press a key and then continue until the next screen is full, and so on:
You can also specify the parameter "/ad". It shows only directories, no files.
For a more detailed explanation of why it shows only directories, see section 7, "File attributes".
Note that dir accepts tons of other parameters. All DOS commands will provide
an overview of the parameters they accept if you invoke them with the "/?" parameter,
e.g.
5. Directories
5.1 Changing the directory
If you are in A:\> and would like to see the content of the subdirectory TEST, you
must first change into that directory. This is done using the "cd" command
("cd" stands for "change directory"). It must be followed by the
name of the directory:
Please note that DOS is NOT case-sensitive, e.g. it doesn't matter which
combination of majuscules and minuscules you use. TEST is equivalent to test
which is equivalent to tEsT, which is equivalent to TEst, etc.
You may now for example use the dir command to inspect the content of the directory.
To go back to the directory you came from, type in "cd..". This will tell
DOS to go back one step in the directory hierarchy:
You can also specify the path of a directory (the path is the full name of the
directory including the drive letter):
A:\TEST>cd a:\hello
A:\HELLO>
|
5.2 Creating and deleting directories
Use the "md" ("make directory") command followed by a name to create a directory, e.g.
Note that file names and directory names must follow certain rules:
- They must contain no more than 8 characters, optionally followed by a dot and
an extension of no more than 3 characters.
- The following characters are NOT allowed because they have a special meaning:
? * / \ : < > |
- The following names are not allowed because they have a special meaning:
nul, con, prn
- They are not case-sensitive
To delete a directory, use the "rd" ("remove directory") command:
Please note that for this work to work, the directory must be empty, e.g. it must not
contain any files or subdirectories! Of course, you cannot delete the directory you
are in, so you first have to change to another directory.
If you want to delete a directory including its subdirectories and files,
use the "deltree" program. (It may or may not be on your boot disk):
Caution! Deltree is extremely destructive! It will ask you for confirmation
before it proceeds. Think twice before you use it!
6. File management
6.1 Deleting files
A file can be deleted using the "del" command:
Note that DOS will not ask for confirmation before it deletes the file!
If you want to delete all files in a directory, use so-called "wildcards":
This will delete all files in the current directory. DOS will ask for confirmation
first, but only once for all files! It will not ask you to confirm the deletion of
each file!
The asterisk * stands for a sequence of characters of arbitrary length; you can
also use the ? character which stands only for one character. For example, the
following commands deletes all files that start with "letter" followed
by any character, and regardless of their extension:
Note that most other DOS commands accept wildcards as well!
6.2 Copying files
Copying files is done using the "copy" command:
|
A:\>copy letter.txt c:\document
|
The first parameter is the source, the second parameter is the destination. If
you omit the destination, then DOS considers the current directory to be the destination:
|
A:\>copy a:\test\letter.txt
|
This copies the file letter.txt from the directory
A:\test
to the current directory, which is
A:\
.
If you want to move a file (e.g. copying a file and then deleting the source file), use
the "move" program. It may or may not be on your boot disk. Note that you must
always specify a destination. Except for this particularity, the syntax is the same for
copying and moving.
6.3 Renaming a file
You may change the name of a file using the "ren" command. Note that
there cannot be two or more files of the same name in the same directory! Of
course, the new filename must follow the rules mentioned in section 5.2.
|
A:\>ren oldname.txt newname.txt
|
6.4 Viewing and modifying a file
The "type" command allows you to view a file that contains
readable content (for example text files). Depending on how many lines the file
consists of, you will observe the same phenomenon as with the dir command mentioned
above: the screen will scroll quickly and you will see only the last lines of the file.
However, the "type" command does not know the "/p" parameter.
You must combine the "type" command with the "more" command.
I will just present the syntax to you, you do not need to know how
it works, you just need to know that it works:
|
A:\>type autoexec.bat | more
|
To modify a text file, you can use the DOS editor. Its name is edit.com (type "edit" at the prompt). Just run it; it has a user interface which should not pose problems to you as a Windows user. Note that if you don't have a mouse or your boot disk offers no mouse support,
you can activate the menu bar by pressing the "Alt" key on your keyboard. You can
then navigate through the menus using the arrow keys and the Enter key. To leave the menu bar,
press Esc. You can highlight text by holding down the shift key and using the arrow keys.
7. File attributes
Every file and directory has certain attributes that characterize it. For example, attributes determine whether a file may be modified ("read-only" attribute), whether it is shown by the "dir" command ("hidden" attribute) or whether it is a system file ("system" attribute). There is also an "archive" attribute but it matters
only when you are creating back-ups so we are not going to discuss it here. Finally there
is the "directory" attribute. It marks a directory - there is nothing magical about it.
|
Regular file |
Read-only |
Hidden |
System |
| Shown by "dir" |
Yes |
Yes |
No |
No |
| Can be modified |
Yes |
No |
Yes |
Yes |
| Can be deleted |
Yes |
No |
No |
No |
| Can be copied |
Yes |
Yes |
No |
Yes |
| Can be renamed |
Yes |
Yes |
No |
Yes |
Note that the "no" is stronger than the "yes". For example,
a read-only file will be shown by dir - however, if it's read-only and hidden,
then it will not be displayed because of the hidden attribute.
The "attrib" program enables you to set or delete attributes. If you
execute it without any parameter, it displays the current attributes of all
files in the current directory:
C:\test>attrib
A S SYSTEM.TXT
A H HIDDEN.TXT
A R READONLY.TXT
A SHR ALL.TXT
A NONE.TXT
|
The "A" stands for the "archive" attribute; again, you may ignore it.
Remember that you can use "more" if the screen scrolls. See section 6.4
To set/remove an attribute, specify a + or - followed by the attribute letter and the filename
or wildcards:
|
A:\>attrib +h -r letter.txt
|
|
A:\>attrib +h -r + s *.dat
|
Note that you can tell the dir command to display only files that have a certain
attribute. Use the /a parameter directly followed by the letter that stands for
the attribute you want to filter out, for example
displays only hidden files.
8. Other DOS commands
8.1 Path
When you enter a command, the command interpreter first verifies whether it knows the
command. If so, it executes it. If it does not recognize the command, it searches for
a file whose name consists of what you entered plus the extension .com (of course it
won't add ".com" if the string you entered already ends with ".com"). If there is still no such file, it searches for a file with the extension .exe, and then .bat. If
it can't find any file, it displays the "Bad command or file name" error message. If, however,
there is such a file, it launches it.
But where does the command interpreter search for these files? If you specify the
directoy of the file you want to launch, it checks whether the file exists in that directory. If you do not specify the path of the file, it searches in the current directory, and then in a list of directories known as the "path". It determines where command.com should search for executable files. You can
display its current content by typing "path" at the DOS prompt:
A:\>path
PATH=A:\;A:\TEST
A:\>
|
Note that the first directory will be searched first, then the second, etc.
You can set the path by entering the "path" command followed by a list
of directories separated by semi-colons.
To append a directory to the existing path, use the "command" followed by
the word "path" between percentage signs ("%") followed by a
semi-colon and then the directory.
A:\>path
PATH=A:\;A:\TEST
A:\>path a:\hello
A:\>path
PATH=A:\HELLO
A:\>path %path%;a:\letters
A:\>path
PATH=A:\HELLO;A:\LETTERS
A:\>
|
8.2 Memory
Use the "mem" program to display the amount of used and free memory.
mem /c displays a list of loaded modules and the
amount of memory they consume.
Use the "/p" parameter to cause mem to wait after it has filled a screen
(it works exactly the same as with the "dir" command)
Please note that mem is a program. It may or may not be on your boot disk.
8.2 Time and date
Enter "time" to display the current time. You may enter a new time or simply
press Enter if you don't want to enter a new time. The same applies to "date".
8.3 Clearing the screen
Type in "cls" to clear the screen.
9. Config.sys, autoexec.bat, io.sys and msdos.sys
The two text files autoexec.bat and config.sys should be on your boot disk. They serve
special purposes.
9.1 Config.sys
This file loads certain device drivers to memory and may contain some configuration
information for DOS. A line starting with "device" or "devicehigh"
loads a device driver. There is a slight difference between the two, but you don't need
to care about it - from our point of view, they do the same. If in doubt, use "device".
The "REM" ("remark") command is of paramount importance.
DOS ignores a line starting with REM. This allows you to temporarily disable a device
driver without having to delete the corresponding line (for the changes to take
effect, you have to reboot because DOS reads the contents of config.sys only on start-up).
Of course, you may use a line starting with REM to insert comments.
9.2 Autoexec.bat
Autoexec.bat is a "batch" file. A batch file contains a batch of DOS commands
that are executed in succession. Batch files come in handy when you often have to carry
out the same task. Autoexec.bat is executed on start-up. It may specify the keyboard
layout for your country, run a certain program, display a welcome message, things like that.
Of course, you may edit autoexec.bat as well. It also knows the REM command (see above).
9.3 Io.sys and msdos.sys
These are extremely important system files. Basically, io.sys is DOS. Command.com
is just a user interface to io.sys. Msdos.sys is also part of DOS in older DOS versions.
In recent DOS versions, it is an editable text file, but you really shouldn't bother with
either of these files. They are usually hidden and must not be deleted under any circumstances!!
They must be in the root directory of the disk!
© Claymania Creations 2001 - 2010. All rights reserved.
Updated: June 4, 2001
|