home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume12 / safe-rm.csh / part01 / safe-rm < prev   
Encoding:
Text File  |  1990-04-13  |  1.4 KB  |  72 lines

  1. #!/bin/csh -f
  2. #
  3. #  Sample Use:    safe-rm file1 file2 dir1 dir2
  4. #
  5. #  Author :    Peter W. Flur
  6. #              Georgia Institute of Technology
  7. #                School of Electrical Engineering
  8. #            
  9. #  Address:    Box 32500
  10. #              Georgia Institute of Technology
  11. #        Atlanta, GA  30332
  12. #
  13. #  Phone:    (404) 583-9355
  14. #
  15. #  E-mail:    flur@duke.gatech.edu
  16. #
  17. #  Description:    This script uses the csh to provide a trashcan 
  18. #        analogy in unix.  A directory defined by the 
  19. #        environment variable TRASH is created and used        
  20. #        to copy files into.  A weekly script or something 
  21. #        of that nature can be used to clean out the trashcan.
  22. #  
  23. #  Advice:    Probably should be used by aliasing the rm command to safe-rm.
  24. #
  25.  
  26. set PATH=/bin
  27. set TRASH=$HOME/.trash
  28.  
  29. if !( -d $TRASH ) then
  30. #  echo "safe-rm:  Trash Can does not exist.  Creating a new can."
  31.   mkdir $TRASH
  32. endif
  33.  
  34. if ( $#argv <= 0 ) then
  35.   echo "Usage: safe-rm [-r] <file> [<file> ...]"
  36.   exit 0
  37. endif
  38.  
  39. if ( "$argv[1]" == '-r' ) then
  40.   set RECURSE=1
  41. else
  42.   set RECURSE=0
  43. endif
  44.  
  45. while ( $#argv > 0 ) 
  46.  
  47.   if ( -f $argv[1] ) then
  48.  
  49.     mv $argv[1] $TRASH/$argv[1].$$
  50.  
  51.     if ($status) then
  52.       tar cf - $argv[1] | (cd $TRASH; tar xf -)
  53.       /bin/rm -fr $argv[1].$$
  54.     endif
  55.  
  56.   else
  57.  
  58.     if ( $RECURSE == 1 ) then
  59.       if ( -d $argv[1] ) then
  60.         mv $argv[1] $argv[1].$$
  61.         tar cf - $argv[1].$$ | (cd $TRASH; tar xf -)
  62.         /bin/rm -fr $argv[1].$$
  63.       endif
  64.     else
  65.       echo safe-rm: $argv[1] directory
  66.     endif
  67.  
  68.   endif
  69.  
  70.   shift
  71. end
  72.