Using the DOS Command-line
Today, most of us comunicate
with our computers by using a Graphic User Interface (GUI) such as Microsoft
Windows, instead of by using a Command Line Interface (CLI). As a flegeling
programmer, however, you'll find that there are some things that are difficult
to do from a GUI. In this lesson, you'll get a quick introduction to DOS,
the CLI that underlies MS Windows. The goal will be to teach you enough
to get through the semester, not to make you into a master of DOS aracana.
DOS commands are typed into a DOS window, which you
can launch by clicking Start, clicking Programs, and then clicking MS DOS
Prompt as shown here:
|
| C:\WINDOWS\SYSTEM> |
it means that the current directory is the SYSTEM directory, which is a subdirectory of the WINDOWS directory stored on the C: drive. A series of directories like this, joined together using backslash characters, is known as a path. (This is just like the path used in a URL, except that URL paths follow the UNIX convention of a forward slash instead of a backslash.)

Here's another example. Suppose you want to move to the C:\WINDOWS\SYSTEM directory. You simply type the full path name of the desired destination:

| cd .. |
For example, if you are in the C:\WINDOWS\SYSTEM directory typing this command will take you to the C:\WINDOWS directory.
If you want to move to a subdirectory of your
current directory (a child directory, in other words), you can just type
the directory name, rather than the complete path. If you are in the C:\WINDOWS
directory and you want to move to the C:\WINDOWS\SYSTEM directory.
You can simply type
| cd SYSTEM |
rather than
| cd C:\WINDOWS\SYSTEM |
In Windows, many folder names, such as "My
Documents" and "Program Files" contain spaces, unlike the
original version of DOS, where file and folder names were limited to eight
characters and a three-character extension. To handle a pathname that contains
spaces, put quotes around the name, like this:
| cd "C:\My Documents\MyWebPages\" |
To change from one drive to another, you don't use the cd command. Instead, you just type the name of the drive followed by a colon like this:


There are some other parts of the directory listing that you might find of interest:
| dir C:\WINDOWS |
lists the contents of the C:\WINDOWS
directory. If you attempt this, you'll find that there are too many lines
to fit in the DOS window, and so the files will scroll off the top of the
window. To prevent this, add the /p flag to the end of the dir
command:
| dir C:\WINDOWS /p |
This causes the listing to stop each time the window fills up. You can read the listing and then press Enter to view the next page.
| del README.TXT |
When using the command-line, deleted files are not placed in the "Recycle Bin", and there is no friendly prompt asking "Are you sure?": the file is instantly and silently deleted from your drive.
| del *.class |
In the same way, you can delete all the
files in the current directory by simply typing
| del *.* |
Obviously, this is very powerful, so be extra-careful when you use wildcards. If you accidentally type del *.java, when you meant to type del *.class, all of your .java files in the current directory will be erased; you will not be able to get them back.
| copy index.html C:\TEMP\ |
Just like with del, you can use wildcards
with the copy command. To copy all the HTML files the current directory
to your A: drive, you would type
| copy *.html A:\ |
You can use the copy command to rename
or move a file. To rename MyApplet.java to MyFirstApplet.java,
you could type the following two commands:
| copy MyApplet.java MyFirstApplet.java
del MyApplet.java |
This is relatively inefficient, however, since
it takes time to copy all the bytes and there must be room on the drive
for both the original file and the new file. A better approach is to use
the ren command, which can also be written rename. For example,
you could accomplish the same thing as the previous example by typing
| ren MyApplet.java MyFirstApplet.java |
Because the ren command doesn't actually move the bytes of the file, both the original file and the new file must be in the same directory.
| md MyJavaFiles |
The directory is created as a subdirectory of
the current directory. If you like, you can create the directory as a subdirectory
elsewhere by typing the full path name of the directory you want to create.
For example, to create a directory named MyJavaFiles that is a
subdirectory of C:\My Documents, you can type
| md "C:\My Documents\MyJavaFiles" |
Notice that we've used quotes around the directory name because the parent directory, (My Documents) has a space in it. In Windows 95 and 98, the parent directory must already exist. Windows NT and 2K will create the necessary parent directories.
To delete a directory, you use the rd command,
which can also be written rmdir. The directory must be empty; that
is, it must not contain any files or subdirectories. It must also not be
the current working directory of any DOS window or running program. To
delete a directory named C:\MUD, type
| rd C:\MUD |
The directory is instantly and silently deleted.
If you're in a hurry, you can delete a directory and all the files
and subdirectories it contains by using the /s flag. Typing
| rd C:\MUD /s |
will delete the C:\MUD directory and all it contains. But, DOS will politely ask you if you're sure before completing the irreversible deletion.
| C:\MyFiles> edit |
When the Edit program starts up, it will use the entire MS-DOS window like this:

When you start a Windows program from a DOS window, it does not run "inside" the DOS window, but launches it's own Window. To use Windows Notepad to create a C++ file called MyProgram.cpp, you'd simply type Notepad MyProgram.cpp and press ENTER like this:
