home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Supreme Volume 6 #1
/
swsii.zip
/
swsii
/
201
/
IO1093.ZIP
/
TECH01.TXT
< prev
next >
Wrap
Text File
|
1993-09-30
|
18KB
|
436 lines
The Secret Life of DOS Commands
Ken Johnson, Chicago Computer Society
You're probably like most PC users who look upon DOS as a
"necessary evil" in you computer life. You need it to run your
PC and all that wonderful software you use. But DOS itself isn't
the most friendly thing in the world. It has cryptic commands
you have to enter one line at a time. Make a mistake and you
have to do it again. And heaven forbid you forget a parameter in
the wrong place (like during FORMAT).
Well, don't give up completely on DOS. DOS has some little used
commands and command features that can actually make your
computing easier. Some are commands that are often overlooked.
Some are unexpected capabilities of commands you already know.
We'll review some of these "DOS Secrets" in this article.
PROMPT
Do you ever get confused navigating through the various
subdirectories on your hard drive? Or looking for a way of
personalizing DOS? Try the PROMPT Command. Using PROMPT can end
directory confusion -- you'll always know where you are!
You've seen the default DOS prompt hundreds of times: the
infamous "C>". Use the PROMPT command to change C> to something
a little more friendly (or frivolous):
PROMPT [prompt_text]
The "prompt_text" is any string of text or special characters.
These special characters will display system information as part
of your prompt:
$P -- the default directory $T -- the current time
(HH:MM:SS.xx) $D -- the current date (MM-DD-YY) $V -- the DOS
version $N -- the default drive $_ -- Carriage Return plus
Line Feed (forces the cursor to the line below) $G -- the >
character $L -- the < character $B -- the | character $Q --
the = character
As you can see, the standard DOS prompt is $N$G, the default
drive and the ">" sign. If you enter the PROMPT command with
nothing after it, DOS resets the prompt to this default.
Lets look at some examples:
PROMPT $P$G -- DOS will display the current drive and current
directory, with the greater than sign. Now you'll never be lost
in your hard drive. For example, if you are in the DOCS
directory of the WP directory on your C: drive, your prompt will
show:
C:\WP\DOCS>_
PROMPT $P$_Enter a Command--$G
-- This will give you a two level prompt:
C:\WP\DOCS
Enter a Command-->_
PROMPT The Date is $T$_Your Current Disk is $N$_Your Current
Directory is $P$_Your Command, oh Master: -- This prompt makes
people think you have REALLY tamed DOS:
The Date is 01-10-91
Your Current Disk is C
Your Current Directory is C:\WP\DOCS
Your Command, oh Master:_
There is one minor problem when having DOS display the current
directory ($P). Each time you press Enter, DOS will read the
disk to figure out the correct directory for the prompt. If your
default drive is a floppy drive and you take the disk out, DOS
will try to read the empty drive and you'll get an error message:
Not ready reading drive A:
Abort, Retry, Fail?
At this point you can put the disk back in and press R. Or you
can simply press F, in which case your prompt will become:
Current drive is no longer valid>_
Just change back to your hard drive and your prompt will
reappear.
CHKDSK
The CHKDSK command is most commonly used to check RAM and files
on your hard disk, and optionally repair some file allocation
problems. But, did you know that CHKDSK also can report on file
fragmentation? And that CHKDSK can show you hidden files on your
disk?
The CHKDSK syntax is:
CHKDSK [d:][filespec] [/F] [/V]
The /F switch is used to fix any problems that CHKDSK finds.
CHKDSK looks for lost clusters, and converts them into files.
Lost clusters are clusters that have been allocated in the File
Allocation Table (FAT), but have no entries in the disk
directory. CHKDSK stores these clusters into files named
FILEnnnn.CHK in the root directory (FILE0000.CHK, FILE0001.CHK,
etc.). You can then look at these files to see if there is any
usable information in them.
When you specify a file specification, CHKDSK will check to see
if the file(s) are stored in contiguous sectors on the disk (that
is, if the files are fragmented). Files stored in contiguous
sectors can be read and updated faster than fragmented files.
The /V switch (Verbose) will cause CHKDSK to list all filenames
as it runs, including hidden files. In fact, CHKDSK /V is the
only DOS command that will show you hidden files.
Some examples:
CHKDSK /F
-- Display a status report on the default drive and repair file
errors.
CHKDSK A:*.*
-- Display a status report on file fragmentation for all files on
drive A:.
CHKDSK C:*.* /V
-- Displays a file status of the hard drive and displays a list
of all files and directories, including hidden files.
Be aware that there is quirk with the CHKDSK command. It will
not fix errors unless you use the /F switch. If you don't use /F
and errors are found, you will be asked if you want them
repaired. It doesn't matter what you answer because the errors
won't be fixed. Just say NO and rerun CHKDSK with /F.
COPY
Okay, the COPY command is probably the second DOS command you
ever learned (right after DIR). But even this basic command has
some tricks up it's sleeve. Did you know you can use COPY to
create or add to an ASCII text file from the keyboard?
The basic form of the COPY command is:
COPY [d:]source_filespec [d:][target_filespec]
The trick to creating files is using COPY with the DOS reserved
device name CON. CON stands for CONsole (or keyboard) and is the
"source_file". The "target_file" is the text file you are
creating. For example, to create an AUTOEXEC.BAT file from the
keyboard, you would enter:
COPY CON AUTOEXEC.BAT
Just enter the lines of text you want, pressing Enter after each
line. When you are done with the last line, press [F6] (or Ctrl-
Z). DOS will enter ^Z, it's end-of-file marker. Press Enter
again and the file is written to the disk. A reminder: DOS is a
very basic line editor; once you've typed a line and pressed
Enter, you can't go back and change that line. You'll have to
start over. (Press Ctrl-Break to cancel creating a file with COPY
CON).
COPY also has another interesting function - to concatenate two
or more files into a larger file. Though this feature doesn't
have much practical use today (and is somewhat cumbersome to
use), it can be used with the CONsole device name to add to
existing text files.
Let's say you need to add a new statement to the end of your
CONFIG.SYS file. You would enter:
COPY CONFIG.SYS + CON
This statement tells DOS to concatenate keyboard input (+ CON) to
the end of the CONFIG.SYS file. Just type in the new statement,
then press [F6] (or Ctrl-Z) and Enter when done. Your new
statement will be added to the file.
LABEL
You probably know the LABEL command as a way to label your floppy
disks. But did you know that the LABEL can help you prevent an
accidental format of your hard drive?
The LABEL command syntax is very simple:
LABEL drive:NewLabel
If you don't specify the new label, DOS will display the current
volume label (if any), and prompt you for a new label. The
volume label can be up to 11 characters, and can include spaces
but can't include a period (just the reverse of DOS file names).
If you press Enter without typing in a label, you will remove the
label (in effect assigning a "blank" volume label).
One secret of the volume label is that in DOS 3.2 and above, you
cannot format a hard disk without entering the volume label. If
you try to format C:, and ignore the "WARNING, ALL DATA ON NON-
REMOVABLE DISK DRIVE C: WILL BE LOST!" message, DOS will prompt
you to "Enter current Volume Label for Drive C:". If you enter
anything other than the correct volume label, the format will
fail with an "Invalid Volume ID" message.
One word of warning. If you don't have a volume label on you
hard drive, pressing Enter when asked for the current volume
label IS a match. Nothing matches Nothing, and the Format
command will continue. That is why it is always a good idea to
label all your hard drives.
By the way, this trick doesn't apply to floppy disks. FORMAT
won't prompt you for a label before it formats a floppy disk.
ATTRIB
The ATTRIBute command was introduced in DOS 3.0, and enhanced
with DOS 3.2 and 3.3. The ATTRIBute command allows you to
display the attributes of a file, and change both the Read-Only
attribute and the Archive attribute. The syntax is:
ATTRIB [+R or -R][+A or -A] [d:]filespec [/S]
The +R switch makes a file Read-only. You cannot delete it or
modify it. The -R switch changes this attribute back to normal,
meaning the file can be changed.
The +A and -A switch is available in DOS 3.2 and above. It
allows you to change the Archive attribute of a file. The
archive attribute is turned on whenever a file is created or
modified. When a file is backed up (with DOS' BACKUP or XCOPY
commands, or a utility program), the archive attribute is turned
off. This attribute allows you to backup only those files
created or changed since your last backup.
The +A switch allows you to make it appear that a file has been
modified, so that it will be backed up by the backup program you
are using. Likewise, you can use -A to exclude a file from being
backed up.
The /S switch was introduced in DOS 3.3. This switch applies the
attribute change to files in the current directory and all child
subdirectories. When executed from the root directory, it will
operate on files that match the filespec in ANY directory.
If you don't specify R or A, the current attribute for the
filespec is displayed. This filespec can contain wildcard
characters.
Some examples:
ATTRIB +R C:\DOS\*.EXE
ATTRIB +R C:\DOS\*.COM
-- These two commands will make the DOS program files in your DOS
subdirectory Read-Only. They cannot be changed or deleted.
ATTRIB *.*
-- Lists the attributes of the files in the current directory.
But, remember that hidden files will not be listed.
ATTRIB +A C:\*.* /S
-- All files in all directories of drive C: are marked as "not
backed up" (e.g., archive attribute is set on).
ATTRIB -A C:\LOTUS\*.*
ATTRIB +A C:\LOTUS\*.WK?
ATTRIB +A C:\LOTUS\*.PRN
BACKUP C:\LOTUS\*.* A: /M
-- This sequence of commands will backup all worksheet and print
files from a LOTUS subdirectory on C: to the A: drive. First,
the archive attribute is turned off for all files (-A), then
turned on (+A) for worksheet files (*.WK?) and print files
(*.PRN). Next, the DOS BACKUP command is executed with the /M
switch; this switch limits BACKUP only the those files with the
archive attribute turned on.
ATTRIB C:\*.BAT /S
-- This is your very own "WhereIs" file. ATTRIBute will display
the attribute of every .BAT file in all directories on the C:
drive. The listing will give the full path of each file, helping
you "find" those lost files.
Before leaving ATTRIB, you might be interested to know there are
two other attributes for a file: Hidden and System. The
ATTRIBute command cannot operate on these attributes (for
example, you can't hide a file). To change these attributes,
you'll need a utility program such as Norton Utilities or
PCShell.
XCOPY
The XCOPY command is one of the real hidden jewels of DOS.
Introduced in DOS 3.2, you can use it as an alternative to the
COPY and the BACKUP commands. XCOPY copies files and can include
files from child subdirectories. XCOPY uses all available RAM for
copying, reading as much of the files into memory before writing
them. Not only is it much faster than the COPY command, you also
can selectively copy files by their date or modification status.
The syntax for XCOPY is:
XCOPY d:source_filespec d:target_filespec [/S] [/E]
[/D:mm-dd-yy] [/A or /M] [/P] [/W] [/V]
The /S switch copies files in child Subdirectories as well as the
specified directory. The /E switch will create Empty directories
on the target, even if no files are copied into those
directories. The /D:mm-dd-yy switch will copy only those files
with a file Date greater than or equal to mm-dd-yy.
The /A switch will only copy those files with the archive
attribute turned on. The /M switch does the same thing, but
resets the archive attribute after the copy. You can use either
/A or /M, but not both.
The last three switches are used infrequently, since they slow
down the operation of the command. The /P switch Prompts you
before each file is copied. The /W switch Waits for you to
insert a disk into the source. The /V switch causes XCOPY to
Verify each copy it makes.
XCOPY is preferred over COPY for many reasons. By using all
available RAM, copying is much faster. XCOPY will create
directories on the target, as well as search though all
subdirectories on the source for file matches. With the /M, /A,
and /D switches, you can select a subset of files to copy.
If you are using DOS 3.3 or 4.0, perhaps the most powerful use of
XCOPY is as an alternative to DOS' BACKUP command. Not only is
it much faster, but copied files can be restored with the COPY
command (you don't have to mess around with RESTORE). But there
are a couple of things to keep in mind. XCOPY cannot copy files
larger than a single diskette (BACKUP is the only DOS choice
then). It will not copy hidden files. XCOPY does not overwrite
existing files on the target, so the disks should be formatted
and empty. Finally, if you want to backup all files, you need to
use ATTRIB to set the archive attribute on for all files before
starting XCOPY.
If you are using XCOPY for a backup, you will need to use the /M
switch and reexecute the command as the disks fill. When XCOPY
fills a disk, it will stop with a "disk full" message. Repeat
the command, filling disks until all files have been backup up.
(Remember that /M turns the archive attribute off after a file is
copied. Therefore when you reexecute XCOPY files already copied
are ignored).
Some examples:
XCOPY C:\*.DBF A: /S
-- Copies all the .DBF files from all directories of drive C: to
directories of the same name on drive A: If the directories
don't already exist, XCOPY will create them.
XCOPY A:*.* B: /S
-- A much faster alternative to COPY *.*. It will copy all files
from the A: drive to the B: drive, including files in any
subdirectories on A:.
XCOPY C:\LOTUS\*.WK? A: /M
-- Copies all worksheet files that have been modified since the
last BACKUP or XCOPY from the Lotus subdirectory on the C: drive
to the A: drive. The archive attribute is turned off after each
file is copied.
It is easiest to do an XCOPY backup with a batch file. In DOS
3.3 XCOPY will set ERRORLEVEL to 4 for a "disk full" error. You
can check for the ERRORLEVEL then loop back through the batch
file:
REM XCOPY Backup Batch File, DOS 3.3 only
@ECHO OFF
CLS
ECHO -- XCOPY full backup of C: drive --
ATTRIB +A C:\*.* /S
:loop
ECHO Insert blank, formatted disk in A: drive
PAUSE
XCOPY C:\*.* A: /S/M
IF ERRORLEVEL 4 GOTO loop
ECHO -- All Done --
Let's take a closer look at this batch file. The ATTRIB command
turns on the archive attribute for all files on the C: drive. The
ECHO and PAUSE tell you to insert a new disk and press a key to
continue. XCOPY copies all files with the archive attribute on
to the A: drive, and turning the archive attribute off as the
copy is done. When the disk in A: fills, XCOPY ends with an
ERRORLEVEL of 4. This causes the batch file to loop back to the
ECHO and PAUSE commands, then reexecutes XCOPY. Since the
archive attribute has been turned off for files already copied,
those files are ignored on each subsequent time through the batch
file. When all files have been copied, the batch file ends with
the "-- All Done --" message.
Unfortunately, you can't use this batch file with DOS 4.0. In
DOS 4.0 XCOPY no longer sets an ERRORLEVEL code when the disk
fills (an example of DOS "devolution"). You can still use a
batch file, but you have to manually stop the batch program:
REM XCOPY Backup Batch File, DOS 4.0 only
@ECHO OFF
CLS
ECHO -- XCOPY full backup of C: drive --
ATTRIB +A C:\*.* /S
:loop
ECHO Insert blank, formatted disk in A: drive
ECHO or press Ctrl-Break if done.....
PAUSE
XCOPY C:\*.* A: /S/M
GOTO loop
You'll notice that instead of checking ERRORLEVEL, this batch
file does an unconditional loop (and will continue to loop
indefinitely). You'll have to monitor the XCOPY and manually
break out of the backup with Ctrl-Break.
Conclusion
DOS has quite a few tricks up its sleeve, and some of them can
actually make your computing easier and more productive. Don't
forget the "secrets" of common commands like COPY and CHKDSK, and
check out commands you may have overlooked before, like ATTRIB
and XCOPY. Who knows, you might even come to like DOS!