#!/bin/csh -f ############################################################################# # # This script will delete files in a directory except for those listed # in the script variable `keep' (pattern matching can be used). An option # is also available to confirm before anything is deleted. # # Author: James Brewer # Version: 1.0 Date: Apr.2, 2000 ############################################################################# # # Check script arguments... # if($#argv != 0 ) then echo "Usage: $0 exit(-1) endif # # Set script variables... # set dir = /data # Directory to clean onintr goodbail # # Change to data directory.. # if (-d $dir) then cd $dir else echo $0": Directory "$dir" does not exist..." exit (-1) endif # # Files NOT to be deleted # set keep = (`ls -d 200[0-9]_[01][0-9]_[0-3][0-9]` `ls wfi*.fits` \ in.in Daily_Health_Check) set nkeep = `echo $keep | wc -w` echo "Files *not* to be deleted: " echo $keep | adjust echo " " # # Confirm before deleting? # set con = 1 echo -n "Confirm before deleting? [y/n] " set reply = $< if ($reply == 'n') then clear echo "WARNING: Files will be deleted WITHOUT confirmation" sleep 2 set con = 0 endif # # Last chance to change mind... # @ n=10 while ($n > 0) clear echo "WARNING: "$n "seconds to deletion (^c to stop)" @ n -= 1 sleep 1 end # # If interrupted now, files may be lost... # onintr badbail # # Look at each file in directory # foreach file (`ls`) # # Print out file name, and fixed space afterwards... # echo -n $file":" set sze = `echo $file | wc -c` while ($sze < 25) echo -n " " @ sze+=1 end # # Was this file to be kept? # @ n=1 while ($n <= $nkeep) if ($file == $keep[$n]) then @ n=9999 endif @ n+=1 end if ($n == 10000) then echo "On save list" continue endif # # Delete file, w/out confirmation # if !($con) then echo "Deleting without confirmation" rm -rf $file continue endif # # Delete file with confirmation # echo -n "Delete? [y/n] " set reply = $< if ($reply == 'y') then echo " Deleting with confirmation" rm -rf $file else echo " Not deleted" endif end # # Write out an 0readme file... # echo "WARNING: files in this directory are automatically purged \ between observing runs. Do not leave important files here\!" >! 0readme exit(1) goodbail: echo " " echo $0": No files were deleted." exit(-1) badbail: echo " " echo $0": WARNING: Files may have been deleted."