home *** CD-ROM | disk | FTP | other *** search
/ Shareware Supreme Volume 6 #1 / swsii.zip / swsii / 201 / IO1093.ZIP / TECH01.TXT < prev    next >
Text File  |  1993-09-30  |  18KB  |  436 lines

  1.  
  2.                   The Secret Life of DOS Commands
  3.  
  4.                Ken Johnson, Chicago Computer Society
  5.  
  6.  
  7.   You're probably like most PC users who look upon DOS as a
  8.   "necessary evil" in you computer life.  You need it to run your
  9.   PC and all that wonderful software you use.  But DOS itself isn't
  10.   the most friendly thing in the world.  It has cryptic commands
  11.   you have to enter one line at a time.  Make a mistake and you
  12.   have to do it again.  And heaven forbid you forget a parameter in
  13.   the wrong place (like during FORMAT).
  14.  
  15.   Well, don't give up completely on DOS.  DOS has some little used
  16.   commands and command features that can actually make your
  17.   computing easier.  Some are commands that are often overlooked.
  18.   Some are unexpected capabilities of commands you already know.
  19.   We'll review some of these "DOS Secrets" in this article.
  20.  
  21.  
  22.   PROMPT
  23.  
  24.   Do you ever get confused navigating through the various
  25.   subdirectories on your hard drive?  Or looking for a way of
  26.   personalizing DOS?  Try the PROMPT Command.  Using PROMPT can end
  27.   directory confusion -- you'll always know where you are!
  28.  
  29.   You've seen the default DOS prompt hundreds of times:  the
  30.   infamous "C>".  Use the PROMPT command to change C> to something
  31.   a little more friendly (or frivolous):
  32.  
  33.   PROMPT [prompt_text]
  34.  
  35.   The "prompt_text" is any string of text or special characters.
  36.   These special characters will display system information as part
  37.   of your prompt:
  38.  
  39.   $P  --  the default directory $T  --  the current time
  40.   (HH:MM:SS.xx) $D  --  the current date (MM-DD-YY) $V  --  the DOS
  41.   version $N  --  the default drive $_  --  Carriage Return plus
  42.   Line Feed (forces the cursor to the line below) $G  --  the >
  43.   character $L  --  the < character $B  --  the | character $Q  --
  44.   the = character
  45.  
  46.   As you can see, the standard DOS prompt is $N$G, the default
  47.   drive and the ">" sign.  If you enter the PROMPT command with
  48.   nothing after it, DOS resets the prompt to this default.
  49.  
  50.   Lets look at some examples:
  51.  
  52.   PROMPT $P$G -- DOS will display the current drive and current
  53.   directory, with the greater than sign.  Now you'll never be lost
  54.   in your hard drive.  For example, if you are in the DOCS
  55.   directory of the WP directory on your C: drive, your prompt will
  56.   show:
  57.  
  58.        C:\WP\DOCS>_
  59.  
  60.   PROMPT $P$_Enter a Command--$G
  61.   -- This will give you a two level prompt:
  62.  
  63.        C:\WP\DOCS
  64.        Enter a Command-->_
  65.  
  66.   PROMPT The Date is $T$_Your Current Disk is $N$_Your Current
  67.   Directory is $P$_Your Command, oh Master: -- This prompt makes
  68.   people think you have REALLY tamed DOS:
  69.  
  70.        The Date is 01-10-91
  71.        Your Current Disk is C
  72.        Your Current Directory is C:\WP\DOCS
  73.        Your Command, oh Master:_
  74.  
  75.   There is one minor problem when having DOS display the current
  76.   directory ($P).  Each time you press Enter, DOS will read the
  77.   disk to figure out the correct directory for the prompt.  If your
  78.   default drive is a floppy drive and you take the disk out, DOS
  79.   will try to read the empty drive and you'll get an error message:
  80.  
  81.   Not ready reading drive A:
  82.   Abort, Retry, Fail?
  83.  
  84.   At this point you can put the disk back in and press R.  Or you
  85.   can simply press F, in which case your prompt will become:
  86.  
  87.   Current drive is no longer valid>_
  88.  
  89.   Just change back to your hard drive and your prompt will
  90.   reappear.
  91.  
  92.  
  93.   CHKDSK
  94.  
  95.   The CHKDSK command is most commonly used to check RAM and files
  96.   on your hard disk, and optionally repair some file allocation
  97.   problems.  But, did you know that CHKDSK also can report on file
  98.   fragmentation?  And that CHKDSK can show you hidden files on your
  99.   disk?
  100.  
  101.   The CHKDSK syntax is:
  102.  
  103.   CHKDSK [d:][filespec] [/F] [/V]
  104.  
  105.   The /F switch is used to fix any problems that CHKDSK finds.
  106.   CHKDSK looks for lost clusters, and converts them into files.
  107.   Lost clusters are clusters that have been allocated in the File
  108.   Allocation Table (FAT), but have no entries in the disk
  109.   directory.  CHKDSK stores these clusters into files named
  110.   FILEnnnn.CHK in the root directory (FILE0000.CHK, FILE0001.CHK,
  111.   etc.).  You can then look at these files to see if there is any
  112.   usable information in them.
  113.  
  114.   When you specify a file specification, CHKDSK will check to see
  115.   if the file(s) are stored in contiguous sectors on the disk (that
  116.   is, if the files are fragmented).  Files stored in contiguous
  117.   sectors can be read and updated faster than fragmented files.
  118.  
  119.   The /V switch (Verbose) will cause CHKDSK to list all filenames
  120.   as it runs, including hidden files.  In fact, CHKDSK /V is the
  121.   only DOS command that will show you hidden files.
  122.  
  123.   Some examples:
  124.  
  125.   CHKDSK /F
  126.   -- Display a status report on the default drive and repair file
  127.   errors.
  128.  
  129.   CHKDSK A:*.*
  130.   -- Display a status report on file fragmentation for all files on
  131.   drive A:.
  132.  
  133.   CHKDSK C:*.* /V
  134.   -- Displays a file status of the hard drive and displays a list
  135.   of all files and directories, including hidden files.
  136.  
  137.   Be aware that there is quirk with the CHKDSK command.  It will
  138.   not fix errors unless you use the /F switch.  If you don't use /F
  139.   and errors are found, you will be asked if you want them
  140.   repaired.  It doesn't matter what you answer because the errors
  141.   won't be fixed.  Just say NO and rerun CHKDSK with /F.
  142.  
  143.  
  144.   COPY
  145.  
  146.   Okay, the COPY command is probably the second DOS command you
  147.   ever learned (right after DIR).  But even this basic command has
  148.   some tricks up it's sleeve.  Did you know you can use COPY to
  149.   create or add to an ASCII text file from the keyboard?
  150.  
  151.   The basic form of the COPY command is:
  152.  
  153.   COPY [d:]source_filespec [d:][target_filespec]
  154.  
  155.   The trick to creating files is using COPY with the DOS reserved
  156.   device name CON.  CON stands for CONsole (or keyboard) and is the
  157.   "source_file".  The "target_file" is the text file you are
  158.   creating.  For example, to create an AUTOEXEC.BAT file from the
  159.   keyboard, you would enter:
  160.  
  161.   COPY CON AUTOEXEC.BAT
  162.  
  163.   Just enter the lines of text you want, pressing Enter after each
  164.   line.  When you are done with the last line, press [F6] (or Ctrl-
  165.   Z).  DOS will enter ^Z, it's end-of-file marker.  Press Enter
  166.   again and the file is written to the disk.  A reminder:  DOS is a
  167.   very basic line editor; once you've typed a line and pressed
  168.   Enter, you can't go back and change that line.  You'll have to
  169.   start over. (Press Ctrl-Break to cancel creating a file with COPY
  170.   CON).
  171.  
  172.   COPY also has another interesting function - to concatenate two
  173.   or more files into a larger file.  Though this feature doesn't
  174.   have much practical use today (and is somewhat cumbersome to
  175.   use), it can be used with the CONsole device name to add to
  176.   existing text files.
  177.  
  178.   Let's say you need to add a new statement to the end of your
  179.   CONFIG.SYS file.  You would enter:
  180.  
  181.        COPY CONFIG.SYS + CON
  182.  
  183.   This statement tells DOS to concatenate keyboard input (+ CON) to
  184.   the end of the CONFIG.SYS file.  Just type in the new statement,
  185.   then press [F6] (or Ctrl-Z) and Enter when done.  Your new
  186.   statement will be added to the file.
  187.  
  188.  
  189.   LABEL
  190.  
  191.   You probably know the LABEL command as a way to label your floppy
  192.   disks.  But did you know that the LABEL can help you prevent an
  193.   accidental format of your hard drive?
  194.  
  195.   The LABEL command syntax is very simple:
  196.  
  197.   LABEL drive:NewLabel
  198.  
  199.   If you don't specify the new label, DOS will display the current
  200.   volume label (if any), and prompt you for a new label.  The
  201.   volume label can be up to 11 characters, and can include spaces
  202.   but can't include a period (just the reverse of DOS file names).
  203.   If you press Enter without typing in a label, you will remove the
  204.   label (in effect assigning a "blank" volume label).
  205.  
  206.   One secret of the volume label is that in DOS 3.2 and above, you
  207.   cannot format a hard disk without entering the volume label.  If
  208.   you try to format C:, and ignore the "WARNING, ALL DATA ON NON-
  209.   REMOVABLE DISK DRIVE C: WILL BE LOST!" message, DOS will prompt
  210.   you to "Enter current Volume Label for Drive C:".  If you enter
  211.   anything other than the correct volume label, the format will
  212.   fail with an "Invalid Volume ID" message.
  213.  
  214.   One word of warning.  If you don't have a volume label on you
  215.   hard drive, pressing Enter when asked for the current volume
  216.   label IS a match.  Nothing matches Nothing, and the Format
  217.   command will continue.  That is why it is always a good idea to
  218.   label all your hard drives.
  219.  
  220.   By the way, this trick doesn't apply to floppy disks.  FORMAT
  221.   won't prompt you for a label before it formats a floppy disk.
  222.  
  223.  
  224.   ATTRIB
  225.  
  226.   The ATTRIBute command was introduced in DOS 3.0, and enhanced
  227.   with DOS 3.2 and 3.3.  The ATTRIBute command allows you to
  228.   display the attributes of a file, and change both the Read-Only
  229.   attribute and the Archive attribute.  The syntax is:
  230.  
  231.   ATTRIB [+R or -R][+A or -A] [d:]filespec [/S]
  232.  
  233.   The +R switch makes a file Read-only.  You cannot delete it or
  234.   modify it.  The -R switch changes this attribute back to normal,
  235.   meaning the file can be changed.
  236.  
  237.   The +A and -A switch is available in DOS 3.2 and above.  It
  238.   allows you to change the Archive attribute of a file.  The
  239.   archive attribute is turned on whenever a file is created or
  240.   modified.  When a file is backed up (with DOS' BACKUP or XCOPY
  241.   commands, or a utility program), the archive attribute is turned
  242.   off.  This attribute allows you to backup only those files
  243.   created or changed since your last backup.
  244.  
  245.   The +A switch allows you to make it appear that a file has been
  246.   modified, so that it will be backed up by the backup program you
  247.   are using.  Likewise, you can use -A to exclude a file from being
  248.   backed up.
  249.  
  250.   The /S switch was introduced in DOS 3.3.  This switch applies the
  251.   attribute change to files in the current directory and all child
  252.   subdirectories.  When executed from the root directory, it will
  253.   operate on files that match the filespec in ANY directory.
  254.  
  255.   If you don't specify R or A, the current attribute for the
  256.   filespec is displayed.  This filespec can contain wildcard
  257.   characters.
  258.  
  259.   Some examples:
  260.  
  261.   ATTRIB +R C:\DOS\*.EXE
  262.   ATTRIB +R C:\DOS\*.COM
  263.   -- These two commands will make the DOS program files in your DOS
  264.   subdirectory Read-Only.  They cannot be changed or deleted.
  265.  
  266.   ATTRIB *.*
  267.   -- Lists the attributes of the files in the current directory.
  268.   But, remember that hidden files will not be listed.
  269.  
  270.   ATTRIB +A C:\*.* /S
  271.   -- All files in all directories of drive C: are marked as "not
  272.   backed up"  (e.g., archive attribute is set on).
  273.  
  274.   ATTRIB -A C:\LOTUS\*.*
  275.   ATTRIB +A C:\LOTUS\*.WK?
  276.   ATTRIB +A C:\LOTUS\*.PRN
  277.   BACKUP C:\LOTUS\*.* A: /M
  278.   -- This sequence of commands will backup all worksheet and print
  279.   files from a LOTUS subdirectory on C: to the A: drive.  First,
  280.   the archive attribute is turned off for all files (-A), then
  281.   turned on (+A) for worksheet files (*.WK?) and print files
  282.   (*.PRN).  Next, the DOS BACKUP command is executed with the /M
  283.   switch; this switch limits BACKUP only the those files with the
  284.   archive attribute turned on.
  285.  
  286.   ATTRIB C:\*.BAT /S
  287.   -- This is your very own "WhereIs" file.  ATTRIBute will display
  288.   the attribute of every .BAT file in all directories on the C:
  289.   drive.  The listing will give the full path of each file, helping
  290.   you "find" those lost files.
  291.  
  292.   Before leaving ATTRIB, you might be interested to know there are
  293.   two other attributes for a file:  Hidden and System.  The
  294.   ATTRIBute command cannot operate on these attributes (for
  295.   example, you can't hide a file).  To change these attributes,
  296.   you'll need a utility program such as Norton Utilities or
  297.   PCShell.
  298.  
  299.  
  300.   XCOPY
  301.  
  302.   The XCOPY command is one of the real hidden jewels of DOS.
  303.   Introduced in DOS 3.2, you can use it as an alternative to the
  304.   COPY and the BACKUP commands.  XCOPY copies files and can include
  305.   files from child subdirectories. XCOPY uses all available RAM for
  306.   copying, reading as much of the files into memory before writing
  307.   them.  Not only is it much faster than the COPY command, you also
  308.   can selectively copy files by their date or modification status.
  309.  
  310.   The syntax for XCOPY is:
  311.  
  312.   XCOPY d:source_filespec d:target_filespec [/S] [/E]
  313.   [/D:mm-dd-yy] [/A or /M] [/P] [/W] [/V]
  314.  
  315.   The /S switch copies files in child Subdirectories as well as the
  316.   specified directory.  The /E switch will create Empty directories
  317.   on the target, even if no files are copied into those
  318.   directories.  The /D:mm-dd-yy switch will copy only those files
  319.   with a file Date greater than or equal to mm-dd-yy.
  320.  
  321.   The /A switch will only copy those files with the archive
  322.   attribute turned on.  The /M switch does the same thing, but
  323.   resets the archive attribute after the copy.  You can use either
  324.   /A or /M, but not both.
  325.  
  326.   The last three switches are used infrequently, since they slow
  327.   down the operation of the command.  The /P switch Prompts you
  328.   before each file is copied.  The /W switch Waits for you to
  329.   insert a disk into the source.  The /V switch causes XCOPY to
  330.   Verify each copy it makes.
  331.  
  332.   XCOPY is preferred over COPY for many reasons.  By using all
  333.   available RAM, copying is much faster.  XCOPY will create
  334.   directories on the target, as well as search though all
  335.   subdirectories on the source for file matches.  With the /M, /A,
  336.   and /D switches, you can select a subset of files to copy.
  337.  
  338.   If you are using DOS 3.3 or 4.0, perhaps the most powerful use of
  339.   XCOPY is as an alternative to DOS' BACKUP command.  Not only is
  340.   it much faster, but copied files can be restored with the COPY
  341.   command (you don't have to mess around with RESTORE).  But there
  342.   are a couple of things to keep in mind.  XCOPY cannot copy files
  343.   larger than a single diskette (BACKUP is the only DOS choice
  344.   then).  It will not copy hidden files.  XCOPY does not  overwrite
  345.   existing files on the target, so the disks should be formatted
  346.   and empty.  Finally, if you want to backup all files, you need to
  347.   use ATTRIB to set the archive attribute on for all files before
  348.   starting XCOPY.
  349.  
  350.   If you are using XCOPY for a backup, you will need to use the /M
  351.   switch and reexecute the command as the disks fill.  When XCOPY
  352.   fills a disk, it will stop with a "disk full" message.  Repeat
  353.   the command, filling disks until all files have been backup up.
  354.   (Remember that /M turns the archive attribute off after a file is
  355.   copied.  Therefore when you reexecute XCOPY files already copied
  356.   are ignored).
  357.  
  358.   Some examples:
  359.  
  360.   XCOPY C:\*.DBF A: /S
  361.   -- Copies all the .DBF files from all directories of drive C: to
  362.   directories of the same name on drive A:  If the directories
  363.   don't already exist, XCOPY will create them.
  364.  
  365.   XCOPY A:*.* B: /S
  366.   -- A much faster alternative to COPY *.*.  It will copy all files
  367.   from the A: drive to the B: drive, including files in any
  368.   subdirectories on A:.
  369.  
  370.   XCOPY C:\LOTUS\*.WK? A: /M
  371.   -- Copies all worksheet files that have been modified since the
  372.   last BACKUP or XCOPY from the Lotus subdirectory on the C: drive
  373.   to the A: drive.  The archive attribute is turned off after each
  374.   file is copied.
  375.  
  376.   It is easiest to do an XCOPY backup with a batch file.  In DOS
  377.   3.3 XCOPY will set ERRORLEVEL to 4 for a "disk full" error.  You
  378.   can check for the ERRORLEVEL then loop back through the batch
  379.   file:
  380.  
  381.   REM XCOPY Backup Batch File, DOS 3.3 only
  382.   @ECHO OFF
  383.   CLS
  384.   ECHO -- XCOPY full backup of C: drive --
  385.   ATTRIB +A C:\*.* /S
  386.   :loop
  387.   ECHO Insert blank, formatted disk in A: drive
  388.   PAUSE
  389.   XCOPY C:\*.* A: /S/M
  390.   IF ERRORLEVEL 4 GOTO loop
  391.   ECHO -- All Done --
  392.  
  393.   Let's take a closer look at this batch file.  The ATTRIB command
  394.   turns on the archive attribute for all files on the C: drive. The
  395.   ECHO and PAUSE tell you to insert a new disk and press a key to
  396.   continue.  XCOPY copies all files with the archive attribute on
  397.   to the A: drive, and turning the archive attribute off as the
  398.   copy is done.  When the disk in A: fills, XCOPY ends with an
  399.   ERRORLEVEL of 4.  This causes the batch file to loop back to the
  400.   ECHO and PAUSE commands, then reexecutes XCOPY.  Since the
  401.   archive attribute has been turned off for files already copied,
  402.   those files are ignored on each subsequent time through the batch
  403.   file.  When all files have been copied, the batch file ends with
  404.   the "-- All Done --" message.
  405.  
  406.   Unfortunately, you can't use this batch file with DOS 4.0.  In
  407.   DOS 4.0 XCOPY no longer sets an ERRORLEVEL code when the disk
  408.   fills (an example of DOS "devolution").  You can still use a
  409.   batch file, but you have to manually stop the batch program:
  410.  
  411.   REM XCOPY Backup Batch File, DOS 4.0 only
  412.   @ECHO OFF
  413.   CLS
  414.   ECHO -- XCOPY full backup of C: drive --
  415.   ATTRIB +A C:\*.* /S
  416.   :loop
  417.   ECHO Insert blank, formatted disk in A: drive
  418.   ECHO or press Ctrl-Break if done.....
  419.   PAUSE
  420.   XCOPY C:\*.* A: /S/M
  421.   GOTO loop
  422.  
  423.   You'll notice that instead of checking ERRORLEVEL, this batch
  424.   file does an unconditional loop (and will continue to loop
  425.   indefinitely).  You'll have to monitor the XCOPY and manually
  426.   break out of the backup with Ctrl-Break.
  427.  
  428.  
  429.   Conclusion
  430.  
  431.   DOS has quite a few tricks up its sleeve, and some of them can
  432.   actually make your computing easier and more productive.  Don't
  433.   forget the "secrets" of common commands like COPY and CHKDSK, and
  434.   check out commands you may have overlooked before, like ATTRIB
  435.   and XCOPY.  Who knows, you might even come to like DOS!
  436.