home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / private / mpc93mar.zip / DELUNDEL.DAT < prev    next >
Text File  |  1993-02-16  |  21KB  |  504 lines

  1.  
  2.      Beginners Column
  3.      DELete And UNDELETE
  4.  
  5.  
  6.      by Kenneth Johnson
  7.      Chicago Computer Society
  8.  
  9.      This month's column will continue to look at the basic DOS commands
  10.      by considering DEL (and ERASE), UNDELETE and MIRROR. DEL and ERASE
  11.      delete files from your disk. UNDELETE (added in DOS 5.0) will attempt
  12.      to restore deleted files; sometimes it is successful, sometimes not.
  13.      You can improve UNDELETE's chances by using MIRROR (also added in DOS
  14.      5.0) to monitor and record all deletions. We'll review how to use DEL
  15.      and ERASE safely, and ways to increase the chances of a successful
  16.      recovery with UNDELETE and MIRROR.
  17.  
  18.      By the way, DEL and ERASE do the same thing. They have the save
  19.      command syntax, except the command name itself. For simplicity sake,
  20.      in this column we'll use DEL. But remember you can substitute "ERASE"
  21.      for wherever "DEL" appears.
  22.  
  23.      To understand why UNDELETE works, it is important to know how DOS
  24.      "deletes" a file. DEL and ERASE do not physically remove data from
  25.      the disk, rather the file is "logically" deleted. The information is
  26.      still there, but the space it occupies is marked as free for reuse.
  27.      When DOS writes to the disk again, it may write over the "deleted"
  28.      data. Then it is gone forever.
  29.  
  30.      When a file is deleted, the first character in the file name directory
  31.      listing is altered (actually replaced with a sigma "σ" character).
  32.      The file's entries in the file allocation table (FAT) are also cleared,
  33.      though the data on the disk itself is unchanged. Since the FAT entries
  34.      tell DOS where the file is physically located, from DOS' perspective
  35.      the file is now "gone."
  36.  
  37.      Unerase utilities such as UNDELETE find logically deleted files by
  38.      look for the "sigma" directory entries. They ask you to enter the
  39.      correct first character of the file name, then attempt to reconstruct
  40.      the FAT entries. How successful the reconstruction is varies,
  41.      depending on how fragmented the file was and whether DOS has written
  42.      over any of the data. Files that are fragmented are much harder to put
  43.      back together since the program has to guess how the clusters go
  44.      together, much like a jigsaw puzzle. If DOS has written over any of
  45.      the data, it is impossible to completely recover a file. A partially
  46.      recovered file is likely worthless.
  47.  
  48.      The means that if you accidentally delete a file, it is important to
  49.      undelete it as soon as possible. If DOS writes anything to the disk,
  50.      there is a chance that the deleted file's data will be physically
  51.      overwritten. Do not save or copy files to the disk; stop everything
  52.      and use UNDELETE or another unerase utility. This ensures the best
  53.      chance of recovery.
  54.  
  55.      Another important consideration is that DEL (and ERASE) will not
  56.      delete files that have the Read-only, Hidden, and/or System attribute.
  57.      So one easy way to guard against accidental deletions is to use the
  58.      ATTRIB command to make files Read-only. Of course, you only want to
  59.      make files Read-only if they are rarely or never modified. For example,
  60.      the following will make all .SYS files on the C: drive Read-only:
  61.  
  62.     ATTRIB +R C:\*SYS /S
  63.  
  64.      The "+R" parameter turns on the Read-only attribute. The "/S" switch
  65.      tells DOS to make the change on the selected directory (here the root
  66.      since we've only specified "C:\") and all child subdirectories. Once
  67.      the Read-only attribute is set, any attempt to delete a file will
  68.      return an "Access Denied" message from DOS. To turn off the Read-only
  69.      attribute use the "-R" switch, such as:
  70.  
  71.     ATTRIB -R C:\CONFIG.SYS
  72.  
  73.      The syntax for the DEL and ERASE commands are:
  74.  
  75.     DEL filespec [/P]
  76.     ERASE filespec [/P]
  77.  
  78.      where filespec is the name of the file(s) to delete. The filespec can
  79.      include the drive designation and/or path if the file is not in the
  80.      current directory, and it may contain wildcard characters. However,
  81.      since a wildcard file specification could include files you don't
  82.      really want to delete, you may want to do a DIR command with the
  83.      filespec first. That way you'll see exactly what will be deleted.
  84.  
  85.      There are a couple of special considerations with the DEL and ERASE
  86.      filespec. If the file specification to delete is the name of a
  87.      directory, then DOS will consider it as a request to delete all files
  88.      (*.*) in that directory. For example, if you have a subdirectory under
  89.      the current directory called WPWIN, and issue the following command:
  90.  
  91.     DEL WPWIN
  92.  
  93.      If will be interpreted as
  94.  
  95.     DEL \WPWIN\*.*
  96.  
  97.      You will be prompted with the standard DEL/ERASE warning message when
  98.      using *.* as a filespec:
  99.  
  100.     All the files in directory will be deleted!
  101.     Are you sure (Y/N)?
  102.  
  103.      You'll have to type "Y" and press Enter for the deletions to take
  104.      place.
  105.  
  106.      Another special filespec is the single period, which stands for the
  107.      current directory and all files in it. So indicating:
  108.  
  109.     DEL .
  110.  
  111.      is equivalent to:
  112.  
  113.     DEL *.*
  114.  
  115.      and again you'll be prompted with the "Are your sure (Y/N)?" message.
  116.      The same goes for the double period (..) filespec, which stands for
  117.      the parent directory and all the files in it.
  118.  
  119.      The "/P" switch, added in DOS 4.0, is an important safety enhancement
  120.      to the DEL and ERASE commands. This is the Prompt switch, which
  121.      displays the full path and name of the file to be deleted, and asks
  122.      "Delete (Y/N)?". You must answer "Y" for the deletion to take place.
  123.      When used with a wildcard filespec, DOS will display the path and name
  124.      of every file matching that specification, one at a time, and have you
  125.      confirm the deletion of each. It's a good way of avoiding unpleasant
  126.      wildcard surprises.
  127.  
  128.      You can make the "/P" switch default whenever executing DEL or ERASE
  129.      by setting up two DOSKEY macros. DOSKEY is a DOS 5.0 TSR (Terminate
  130.      and Stay Resident) program that allows you to create macros from the
  131.      command line. What makes these macros so powerful is that they execute
  132.      before the DOS internal commands (commands that are part of
  133.      COMMAND.COM, the command interpreter -- which DEL and ERASE are). This
  134.      means that DOSKEY macros can redefine and customize DOS commands.
  135.  
  136.      DOSKEY is normally loaded in your AUTOEXEC.BAT file. To create the
  137.      prompted delete macros, include the following lines in AUTOEXEC.BAT
  138.      after loading DOSKEY:
  139.  
  140.     DOSKEY DEL=DEL $1 /P
  141.     DOSKEY ERASE=ERASE $1 /P
  142.  
  143.      The "$1" is a replaceable parameter that stands for the file
  144.      specification to delete. Now whenever you enter a DEL or ERASE
  145.      command, DOSKEY will intercept and reissue it to DOS with the /P
  146.      switch. You'll be prompted with the full path and file name and
  147.      asked to confirm the deletion.
  148.  
  149.      Let's look at some examples:
  150.  
  151.      DEL EXPENSES.DB
  152.     Deletes the file EXPENSES.DB in the current directory.
  153.  
  154.      DEL A:*.BAK
  155.     Deletes all files with the ".BAK" extension in the default directory
  156.      on the A: drive. If any of these files have the Read-only, System, or
  157.      Hidden attributes, they will not be deleted.
  158.  
  159.      DEL A:*.BAK /P
  160.     Deletes all the .BAK files in the default directory of the A: drive,
  161.      but prompts you with each file name and asks you to confirm each
  162.      delete. Again, Read-only, Hidden, and System files will not be
  163.      deleted; you'll receive an "Access Denied" message.
  164.  
  165.      DEL *.*
  166.     Deletes all files (except, Read-only, Hidden, or System files) in the
  167.      current directory. You'll be prompted with the following message:
  168.  
  169.         All files in the directory will be deleted!
  170.         Are you sure (Y/N)?
  171.  
  172.     Answer "Y" to proceed with the deletions.
  173.  
  174.      DEL .
  175.     Exactly like the example above, deletes all files (except, Read-only,
  176.      Hidden, or System files) in the current directory. Again you'll be
  177.      prompted with the Are you sure (Y/N)? message.
  178.  
  179.      DEL ..\CCSBBS.ASP /P
  180.     Deletes the file CCSBBS.ASP in the parent directory, prompting you to
  181.      confirm the deletion.
  182.  
  183.      ECHO Y | DEL *.*
  184.     This is an interesting, but dangerous one! Deletes all files (except,
  185.      Read-only, Hidden, or System files) in the current directory, without
  186.      giving you a chance to say you are sure. The ECHO command pipes "Y"
  187.      into the DELETE command, which answers the "Are your sure (Y/N)?"
  188.      message affirmatively. This technique is often used in batch files to
  189.      automatically delete all files without requiring user confirmation.
  190.  
  191.      So what if, despite your best efforts, you accidentally delete an
  192.      important file? Remember that the erased file is probably salvageable
  193.      until new data is written over it. Stop everything and try to recover
  194.      the file as soon as possible. DOS 5.0 includes two recovery programs
  195.      to help get back deleted files: UNDELETE and MIRROR.
  196.  
  197.      The syntax for setting up MIRROR as a delete tracking TSR is:
  198.  
  199.     MIRROR /Td[-nnn]
  200.  
  201.      where "d" is the drive to track and the optional "-nnn" specifies the
  202.      number of entries to keep. MIRROR creates a file name PCTRACKER.DEL in
  203.      the root directory of the specified drive, which contains the names
  204.      and locations of the deleted files. The size of PCTRACKER.DEL depends
  205.      on the number of entries, each of which takes up about 150 bytes. If
  206.      not specified, the number of entries is determined by the size of the
  207.      disk; from 25 for a 360k floppy to over 300 for a 32+ MB hard drive.
  208.  
  209.      For example, suppose you have a C: and a D: drive and want to track
  210.      deletions on each. You could include the following in your
  211.      AUTOEXEC.BAT file:
  212.  
  213.     MIRROR /TC /TD
  214.  
  215.      The delete tracking component of MIRROR can be run from upper memory,
  216.      so if you have a 386 or 486 computer you may want to load it high.
  217.  
  218.      Whether or not you use MIRROR, the UNDELETE program can help recover
  219.      deleted files. With MIRROR's delete tracking, getting back deleted
  220.      files is almost a certainty -- if the data hasn't been physically
  221.      overwritten on the disk. Without the delete tracking file, recover
  222.      with UNDELETE is less certain but still possible. However, be aware
  223.      that UNDELETE cannot restore a removed directory or erased files in
  224.      a removed directory.
  225.  
  226.      The syntax for UNDELETE is:
  227.  
  228.     UNDELETE [filespec] [/DT or /DOS] [/ALL or /LIST]
  229.  
  230.      "Filespec" is the name(s) of the erased file to undelete; it can
  231.      include the drive and/or path if files are not in the current
  232.      directory and can include wildcards. If no file specification is
  233.      given, all deleted files in the current directory are selected.
  234.  
  235.      The "/DT" and "/DOS" switches determine how the undelete will be
  236.      performed. "/DT" indicates to use MIRROR's delete tracking file; only
  237.      those specified files in the PCTRACKR.DEL file will be undeleted, and
  238.      you will be prompted to confirm the undelete of each. To use this
  239.      option, you must be running MIRROR with delete tracking when erasing
  240.      the file you need to recover.
  241.  
  242.      The "/DOS" switch tells UNDELETE to recover based on the directory
  243.      entries, without the aid of a delete tracking file. UNDELETE will find
  244.      the logically deleted directory entries, and ask you to provide the
  245.      correct first letter of each file name (it will be shown as a question
  246.      mark). UNDELETE will replace the name in the directory, then try to
  247.      restore the file's FAT entries as best it can. The success of UNDELETE
  248.      depends on the size of the file and the degree of fragmentation. Use
  249.      the "/DOS" option if you believe that the delete tracking file is out
  250.      of date and should not be used.
  251.  
  252.      The "/ALL" switch will undelete the specified files without prompting.
  253.      If using delete tracking, UNDELETE will automatically recover all
  254.      deleted files using the names and FAT information in the PCTRACKR.DEL
  255.      file. If the original name of a deleted file already exists in the
  256.      directory, you'll be asked for a new name for the undeleted file. When
  257.      no delete tracking file exists, or if you are using the "/DOS" switch,
  258.      UNDELETE will try other symbols (%&-), then numbers, then letters
  259.      until it finds a unique name.
  260.  
  261.      The "/LIST" switch shows what files can be undeleted, without
  262.      performing the undelete. Try this first to see exactly what files are
  263.      available for recovery.
  264.  
  265.      Let's look at some examples of using UNDELETE with and without delete
  266.      tracking. Let's say you've accidentally deleted all the *.TXT files in
  267.      the C:\DOCS subdirectory. First we'll see UNDELETE when there is no
  268.      delete tracking We'll start with /LIST to check what can be undeleted
  269.      (in these examples, the italics represent what you type in):
  270.  
  271.     C:\DOCS>undelete /list
  272.  
  273.      Directory: C:\DOCS
  274.     File Specifications: *.*
  275.  
  276.     MS-DOS directory contains   3 deleted files.
  277.     Of those,   3 files may be recovered.
  278.  
  279.     Using the MS-DOS directory.
  280.  
  281.         ?eadme   txt  33655  4-09-91  5:00a ...A
  282.         ?ppnotes txt   9701  4-09-91  5:00a ...A
  283.         ?oshelp  txt   1540  5-08-91 12:00p ...A
  284.  
  285.      Now let's automatically undelete all the files:
  286.  
  287.     C:\DOCS>undelete /all
  288.  
  289.     Directory: C:\DOCS
  290.     File Specifications: *.*
  291.  
  292.     Deletion-tracking file not found.
  293.  
  294.     MS-DOS directory contains   3 delete files.
  295.     Of those,   3 files may be recovered.
  296.  
  297.     Using the MS-DOS directory.
  298.  
  299.         ?readme  txt  33655  4-09-91  5:00a ...A
  300.  
  301.     File successfully undeleted.
  302.  
  303.         ?ppnotes txt   9701  4-09-91  5:00a ...A
  304.  
  305.     File successfully undeleted.
  306.  
  307.         ?oshelp  txt   1540  5-08-91 12:00p ...A
  308.  
  309.     File successfully undeleted.
  310.  
  311.      To see what we got back, do a DIR command on the .TXT files:
  312.  
  313.     C:\DOCS>dir *.txt
  314.  
  315.     Volume in drive C has no label
  316.     Volume Serial Number is 3352-15EE
  317.     Directory of C:\DOCS
  318.  
  319.                  #eadme   txt  33655  4-09-91  5:00a
  320.                  #ppnotes txt   9701  4-09-91  5:00a
  321.                  #oshelp  txt   1540  5-08-91 12:00p
  322.                         3 file(s)   44896 bytes
  323.                                  36917248 bytes free
  324.  
  325.      Notice that without a delete tracking file and using /ALL, DOS assigns
  326.      the pound sign as the first character of each of the three file names.
  327.      If you undelete files individually, UNDELETE will give you the
  328.      opportunity to supply the correct first letter of the name:
  329.  
  330.     C:\DOCS>undelete doshelp.txt
  331.  
  332.     Directory: C:\DOCS
  333.     File Specifications: DOSHELP.TXT
  334.  
  335.     Deletion-tracking file not found.
  336.  
  337.     MS-DOS directory contains   1 delete files.
  338.     Of those,   1 files may be recovered.
  339.  
  340.     Using the MS-DOS directory.
  341.  
  342.         ?oshelp  txt   1540  5-08-91 12:00p ...A
  343.  
  344.     Undelete (Y/N)? y
  345.     
  346.     Please type the first character for ?OSHELP.TXT: y
  347.  
  348.     File successfully undeleted.
  349.  
  350.      To make sure we got the file back, do a DIR command on the .TXT files:
  351.  
  352.     C:\DOCS>dir *.txt
  353.  
  354.     Volume in drive C has no label
  355.     Volume Serial Number is 3352-15EE
  356.     Directory of C:\DOCS
  357.  
  358.                  DOSHELP  TXT   1540  5-08-91 12:00p
  359.                         3 file(s)    1540 bytes
  360.                                  36917248 bytes free
  361.  
  362.      Now let's look at the same examples when MIRROR has been used to track
  363.      the deletions. You should notice that not only is it easier, but you
  364.      also get additional information about the deletion:
  365.  
  366.     C:\DOCS>undelete /list
  367.  
  368.     Directory: C:\DOCS
  369.     File Specifications: *.*
  370.  
  371.     Deletion-tracking file contains   3 deleted files.
  372.     Of those,   3 files have all clusters available,
  373.                 0 files have some clusters available,
  374.                 0 files have no clusters available.
  375.  
  376.     MS-DOS directory contains   3 deleted files.
  377.     Of those,   3 files may be recovered.
  378.  
  379.     Using the deletion-tracking file.
  380.  
  381.     DOSHELP  TXT    1540  5-08-91 12:00p ...A
  382.         Deleted: 11-12-92  1:30p
  383.     APPNOTES TXT    9701  4-09-91  5:00p ...A
  384.         Deleted: 11-12-92  1:30p
  385.     README   TXT   33655  4-09-91  5:00p ...A
  386.         Deleted: 11-12-92  1:30p
  387.  
  388.      Now we can undelete all files with the file names intact:
  389.  
  390.     C:\DOCS>undelete /all
  391.  
  392.     Directory: C:\DOCS
  393.     File Specifications: *.*
  394.  
  395.     Deletion-tracking file contains   3 deleted files.
  396.     Of those,   3 files have all clusters available,
  397.                 0 files have some clusters available,
  398.                 0 files have no clusters available.
  399.  
  400.     MS-DOS directory contains   3 deleted files.
  401.     Of those,   3 files may be recovered.
  402.  
  403.     Using the deletion-tracking file.
  404.  
  405.     DOSHELP  TXT    1540  5-08-91 12:00p ...A
  406.         Deleted: 11-12-92  1:30p
  407.  
  408.     File successfully undeleted.
  409.  
  410.     Using the deletion-tracking file.
  411.  
  412.     APPNOTES TXT    9701  4-09-91  5:00p ...A
  413.         Deleted: 11-12-92  1:30p
  414.  
  415.     File successfully undeleted.
  416.  
  417.     Using the deletion-tracking file.
  418.  
  419.     README   TXT   33655  4-09-91  5:00p ...A
  420.         Deleted: 11-12-92  1:30p
  421.  
  422.     File successfully undeleted.
  423.  
  424.      You can also undelete one file with ease:
  425.  
  426.     C:\DOCS>undelete doshelp.txt
  427.  
  428.     Directory: C:\DOCS
  429.     File Specifications: DOSHELP.TXT
  430.  
  431.     Deletion-tracking file contains   1 deleted files.
  432.     Of those,   1 files have all clusters available,
  433.                 0 files have some clusters available,
  434.                 0 files have no clusters available.
  435.  
  436.     MS-DOS directory contains   1 deleted files.
  437.     Of those,   1 files may be recovered.
  438.  
  439.     Using the deletion-tracking file.
  440.  
  441.     DOSHELP  TXT    1540  5-08-91 12:00p ...A
  442.         Deleted: 11-12-92  1:30p
  443.  
  444.     All of the clusters for this file are available. Undelete (Y/N)? y
  445.  
  446.     File successfully undeleted.
  447.  
  448.      DEL and ERASE are important, yet dangerous commands. We've looked at
  449.      some way to protect yourself from accidental deletions, and how to
  450.      (hopefully) get back deleted files with UNDELETE and MIRROR. Some
  451.      points to keep in mind when using DEL and ERASE:
  452.  
  453.      -    Undelete ASAP! Since a logically deleted file's data is not
  454.      physically overwritten, there is a chance for recovery. If DOS writes
  455.      anything to the disk, the erased file's data may be physically
  456.      overwritten and thus lost forever. Stop whatever you are doing, don't
  457.      save or copy any files to the disk, and run UNDELETE (or another
  458.      unerase utility).
  459.  
  460.     If you are at the DOS prompt, go to the subdirectory containing the
  461.      deleted file(s) and run UNDELETE. If you are running an application
  462.      program, quit. In the event you must save your work before exiting the
  463.      program, be sure to save to a different drive. When you are not sure
  464.      you can exit without writing to the disk, reboot the computer. However,
  465.      if your AUTOEXEC.BAT file has any programs that write to the disk (like
  466.      MIRROR or DOSSHELL), you should reboot from a "plain" DOS disk in the
  467.      A: drive.
  468.  
  469.      -    Remember that UNDELETE cannot get back removed directories or any
  470.      erased files in a removed directory. Make sure that you really don't
  471.      want any of the deleted files before you remove their directory.
  472.  
  473.      -    Include "mirror /tc" in your AUTOEXEC.BAT to set up delete
  474.      tracking on the C: drive. Include "/td" to monitor the D: drive, "/ta"
  475.      to monitor the A: drive, and so forth. With MIRROR's delete tracking
  476.      you significantly increase the chances of a successful undelete -- as
  477.      long as the file isn't overwritten.
  478.  
  479.      -    Use the /p switch with DEL and ERASE to confirm each deletion,
  480.      especially when using wildcard specifications. Consider using DOSKEY
  481.      to make the /p the default, by including the following two lines in
  482.      your AUTOEXEC.BAT file after loading DOSKEY:
  483.  
  484.         DOSKEY DEL=DEL $1 /P
  485.         DOSKEY ERASE=ERASE $1 /P
  486.  
  487.      -    Be careful with wildcards and directory names with DEL and ERASE.
  488.      Before using a wildcard file specification, use it in a DIR command to
  489.      see exactly what will be deleted. Remember that giving a directory
  490.      name with DEL/ERASE means to delete all files in that directory.
  491.  
  492.      -    Remember that UNDELETE may be able to recover sensitive data that
  493.      you truly want to stay deleted. If you are concerned about sensitive
  494.      information staying unrecoverable, consider a utility program (such as
  495.      Norton Utilities' WIPEINFO or PCTools' WIPE) that will totally
  496.      obliterate data so that it cannot be recovered by any means. To secure
  497.      a floppy disk, unconditionally format it with FORMAT /U. Neither
  498.      UNDELETE nor UNFORMAT can recover any data from the disk.
  499.  
  500.      -    Finally, if you are asked "Are you sure (Y/N)?" and you are not
  501.      totally, absolutely, and positively sure, answer N. DOS doesn't give
  502.      you a second chance or understand the verbal "Oops!" command.
  503.  
  504.