home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / unix_c / filemgmt / del.csh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1989-03-21  |  2.4 KB  |  90 lines

  1. #!/bin/csh -f
  2. #File deletion with options
  3. #Rahul Dhesi 1987/02/25
  4. #revised 1987/02/26
  5. if ($#argv < 1) then
  6.    echo Usage:  del file ...
  7.    exit (1)
  8. endif
  9. foreach file ($*)
  10. again:
  11.    set type='Delete ['`/usr/bin/file "$file"|/bin/sed -e 's/    / /g'`']? [Yes/No/List/Quit] '
  12.    switch ("$type")
  13.       case '*o such file or*'
  14.          echo "Could not find $file"
  15.          goto nextloop
  16.          breaksw
  17.       case '*directory*'
  18.          echo "Skipping $file because it is a directory"
  19.          goto nextloop
  20.          breaksw
  21.       case '*mission denied*'
  22.          echo "Skipping $file because access to it was denied"
  23.          goto nextloop
  24.          breaksw
  25.    endsw
  26.  
  27. ask:
  28.    echo -n "$type"
  29.    set ans=($<)
  30.    switch ("$ans")
  31.       case 'y'
  32.       case 'Y'
  33.          /bin/rm "$file"
  34.      if (-e "$file") then
  35.             echo "Sorry, $file could not be deleted" | \
  36.                /bin/sed -e 's/\([^     ]\)/_\1/g' | \
  37.                /usr/ucb/more
  38.          else
  39.             echo "File $file" has been deleted
  40.          endif
  41.          breaksw
  42.       case 'n'
  43.       case 'N'
  44.          echo "Skipping $file"
  45.          breaksw
  46.       case 'l'
  47.       case 'L'
  48.          switch ("$type")
  49.             case '*text*'
  50.             case '*script*'
  51.                echo '*****' "$file" '*****'
  52.                /bin/cat -uv "$file" | /usr/ucb/more -10d
  53.                breaksw
  54.             case '*empty*'
  55.                echo "***** File $file is empty *****"
  56.                echo '<...empty...>'
  57.                breaksw
  58.             case '*link to*'
  59.                echo "***** Searching for printable strings in $file ... ***"
  60.                /usr/ucb/strings "$file" | /bin/cat -uv | /usr/ucb/more -10dl
  61.                breaksw
  62.             case '*zoo archive*'
  63.                echo -n "***** Archive $file contains: *****"
  64.                /usr/local/zoo l "$file" | /bin/cat -uv | /usr/ucb/more -10dl
  65.                 breaksw
  66.             default
  67.                echo "***** Searching for printable strings in $file ... ***"
  68.                /usr/ucb/strings "$file" | /bin/cat -uv | /usr/ucb/more -10dl
  69.                breaksw
  70.          endsw
  71.          echo '*****'
  72.          goto again
  73.          breaksw
  74.       case 'q'
  75.       case 'Q'
  76.          exit
  77.       default
  78.          echo 'Please type the first letter:  Y, N, L, or Q'
  79.          goto ask
  80.          breaksw
  81.    endsw
  82. nextloop:
  83. end
  84. exit (0)
  85.  
  86. -- 
  87. Rahul Dhesi         UUCP:  {ihnp4,seismo}!{iuvax,pur-ee}!bsu-cs!dhesi
  88.  
  89.  
  90.