home *** CD-ROM | disk | FTP | other *** search
- #!/bin/csh -f
- #
- # Sample Use: safe-rm file1 file2 dir1 dir2
- #
- # Author : Peter W. Flur
- # Georgia Institute of Technology
- # School of Electrical Engineering
- #
- # Address: Box 32500
- # Georgia Institute of Technology
- # Atlanta, GA 30332
- #
- # Phone: (404) 583-9355
- #
- # E-mail: flur@duke.gatech.edu
- #
- # Description: This script uses the csh to provide a trashcan
- # analogy in unix. A directory defined by the
- # environment variable TRASH is created and used
- # to copy files into. A weekly script or something
- # of that nature can be used to clean out the trashcan.
- #
- # Advice: Probably should be used by aliasing the rm command to safe-rm.
- #
-
- set PATH=/bin
- set TRASH=$HOME/.trash
-
- if !( -d $TRASH ) then
- # echo "safe-rm: Trash Can does not exist. Creating a new can."
- mkdir $TRASH
- endif
-
- if ( $#argv <= 0 ) then
- echo "Usage: safe-rm [-r] <file> [<file> ...]"
- exit 0
- endif
-
- if ( "$argv[1]" == '-r' ) then
- set RECURSE=1
- else
- set RECURSE=0
- endif
-
- while ( $#argv > 0 )
-
- if ( -f $argv[1] ) then
-
- mv $argv[1] $TRASH/$argv[1].$$
-
- if ($status) then
- tar cf - $argv[1] | (cd $TRASH; tar xf -)
- /bin/rm -fr $argv[1].$$
- endif
-
- else
-
- if ( $RECURSE == 1 ) then
- if ( -d $argv[1] ) then
- mv $argv[1] $argv[1].$$
- tar cf - $argv[1].$$ | (cd $TRASH; tar xf -)
- /bin/rm -fr $argv[1].$$
- endif
- else
- echo safe-rm: $argv[1] directory
- endif
-
- endif
-
- shift
- end
-