C.1 DOS Commands
You should know the following basic DOS commands to be able
to complete some of the solutions in this book and get by in the world of
Windows.
This, however, should not be considered a comprehensive list
of all DOS commands and their options. See Windows XP
in a Nutshell (O'Reilly) for a more thorough reference, not only on the
Command Prompt, but on all of the various utilities included with Windows XP
that use the Command Prompt.
The commands shown here are in constant width,
and any parameters (the information you supply to the command) are in
constant width italic. It doesn't
matter which case you use when you type them in the command prompt (DOS, like
Windows, is not case-sensitive). If there is more than one parameter, each is
separated by a space:
- attrib
attributes filename
-
Changes the attributes of a file or folder. The four
attributes are R for read only, S for system,
A for archive, and H for hidden.
In Explorer, you can right-click a file or group of files
and select Properties to change the
attributes; attrib is the DOS counterpart to this functionality. In
addition, attrib lets you change the S (system) attribute,
something Explorer doesn't let you do. Here are some examples:
-
attrib +h
myfile.txt—this turns on the H
parameter for the file myfile.txt, making the file hidden.
-
attrib -r "another
file.doc"--this turns off
the R (read-only) parameter for the file another
file.doc (note that quotation marks are used because of the
space in the filename).
Type attrib /? for additional options.
- cd
foldername
-
Changes the working directory to foldername. If
the prompt indicates you are in C:\Windows and you want to enter the
c:\Windows\System32 folder, type cd system32. You can also switch
to any folder on your hard disk by including the full path of the folder. Type
cd .. to go to the parent folder. Type cd by itself to
display the current directory.
To switch to another drive, just type the drive letter,
followed by a colon (:). For example, type a: to switch to the floppy
drive.
- cls
-
Clear the display and empty the buffer (the history of
output accessible with the scrollbar.)
- copy
filename destination
-
Copies a file to another directory or drive, specified by
destination. This is the same as dragging and dropping files in
Explorer, except that the keyboard is used instead of the mouse. For example,
to copy the file myfile.txt (located in the current working directory)
to your floppy drive, type copy myfile.txt a:\. Type copy /?
for additional options.
- del
filename
-
Deletes a file. For example, to delete the file
myfile.txt, type del myfile.txt. This is not exactly the same as
deleting a file in Windows, because the file will
not be stored in the Recycle Bin. The advantage of the DOS variant is
that you can more easily and quickly delete a group of files, such as all the
files with the .tmp extension: del *.tmp. Type del /?
for additional options.
- dir name
-
Displays a listing of all the files and directories in the
current working directory. Use cd to change to a different directory,
or type dir c:\files to display the contents of C:\Files
without having to first use the cd command. Type dir /p to
pause the display after each page, useful for very long listings. You can also
specify wildcards to filter the results; type dir *.tmp to display
only files with the .tmp filename extension. Type dir /? for
additional options.
- echo text
-
Displays the text, text, on the screen, See "Variables and
the Environment," later in this chapter.
- exit
-
Closes the Command Prompt window. In most situations, you
can just click the close button [x] on the
upper-right corner of the Window, but the exit command works just as
well.
- md
foldername
-
Stands for make directory. This command creates a new
directory with the name foldername. The command will have no
effect if there's already a directory or file with the same name.
- move
filename destination
-
Is the same as copy, except that the file is moved
instead of copied. Type move /? for additional options.
- rd
foldername
-
Stands for remove directory. This command removes an
existing directory with the name foldername. The command will
have no effect if the directory is not empty. To remove a directory and all of
its contents, use deltree.
- ren
oldfilename newfilename
-
Renames a file to newfilename. This is
especially useful, because you can use the ren command to rename more
than one file at once—something Explorer doesn't let you do. For example, to
rename hisfile.txt to herfile.txt, type ren hisfile.txt
herfile.txt. To change the extensions of all the files in the current
working directory from .txt to .doc, type ren *.txt *.doc.
Type ren /? for additional options.
- set
[ variable=[
string]]
-
When used without any arguments, displays a list of active
environment variables (described in Section C.2.1, later in this appendix).
The set command is also used to assign data to environment variables.
- TYPE
filename
-
Displays the contents of a text file. Type type
filename | more to display the file and pause between each page of
information rather than displaying the whole file at once.
|
Unlike the DOS window in Windows 9x/Me, the Windows XP
Command Prompt fully supports long filenames. However, given the nature of
the command line, there are times that specifying long filenames will cause
a problem. Specifically, if the file or folder name you're typing contains a
space, you may need to enclose the filename in quotes.
Say you wish to rename a file named my stuff.txt
to her stuff.doc. Instinctively, you might type:
- ren my stuff.txt her stuff.doc
However, this won't work, since the ren command
sees is that you've typed four parameters.
Instead, you'll need to use quotation marks, like this:
- ren "my stuff.txt" "her stuff.doc"
Now, this isn't always the case. For example, if you want
to use the cd command to change the current working directory to
Program Files, like this:
- cd Program Files
the Command Prompt is smart enough to interpret this
correctly, and no quotation marks are needed. |
|
Main Menu
|