Creating a nondestructive 'rm'
Walter Tondu
tondu at felix.UUCP
Sun Nov 6 03:00:11 AEST 1988
In article <4460006 at hpindda.HP.COM> burdick at hpindda.HP.COM (Matt Burdick) writes:
>Does anyone have a nice alias or shell script so that when I 'rm' a file it
>will actually move it to, for instance, a tmp subdirectory in my home
>directory?
>
>Right now, I have an alias that does this, but the problem is that may
>alias doesn't handle all of rm's flags. For instance, it complains if I
>type in 'rm -rf *', since 'mv' doesn't have the -r flag and also can't move
>across file partitions.
>
>--
>Matt Burdick | Hewlett-Packard
>burdick%hpda at hplabs.hp.com | Technical Communications Lab
Here's a solution which I use. This comes from "Tricks of the UNIX
Masters" by Russel G. Sage. Published by Howard W. Sams & Co.
I have modified it a tad in order to fit my needs more exactly
usage:
1) rm -l; - lists all files that have been removed to
- 'can' directory.
2) rm -r; - remove permanently all files that have been
- previously removed.
3) rm -f; - use /bin/rm and force removal.
(strip following code of leading "*".
*:
*# @(#) can v1.0 Maintain trash can
*
*CAN=$HOME/.trashcan
*
*#if [ ! d $CAN ]
*#then
*# mkdir $CAN
*#fi
*
*if [ $# -eq 0 ]
*then
* echo "usage can [-l] [-r] [-f] file [file ...]" >&2
* exit 0
*fi
*
*if [ "`echo \"$1\" | cut -c1`" = "-" ]
*then
* case $1 in
* -l) echo "$CAN:"
* /bin/ls $CAN
* exit 0;;
* -r) echo "removing $CAN/*:"
* /bin/rm -rf $CAN/*
* exit 0;;
* -f) echo "force removal"
* /bin/rm -rf $@
* exit 0;;
* -?) echo "usage can [-l] [-r] file [file ...]" >&2
* exit 0;;
* esac
*fi
*
*mv $@ $CAN
____________________________________________________________
.plan - to indulge whenever possible
walter tondu
____________________________________________________________
More information about the Comp.unix.questions
mailing list