Path: utzoo!attcan!uunet!husc6!mailrus!uflorida!haven!decuac!felix!tondu From: tondu@felix.UUCP (Walter Tondu) Newsgroups: comp.unix.questions Subject: Re: Creating a nondestructive 'rm' Keywords: rm Message-ID: <67991@felix.UUCP> Date: 5 Nov 88 17:00:11 GMT References: <4460006@hpindda.HP.COM> Sender: daemon@felix.UUCP Reply-To: tondu@felix.UUCP (Walter Tondu) Followup-To: burdick@hpindda.HP.COM Organization: FileNet Corp., Costa Mesa, CA Lines: 67 In article <4460006@hpindda.HP.COM> burdick@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@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 ____________________________________________________________