home *** CD-ROM | disk | FTP | other *** search
- Path: xanth!mcnc!gatech!mandrill!hal!ncoast!allbery
- From: koala@uunet.uu.net@chinet.uucp
- Newsgroups: comp.sources.misc
- Subject: v03i074: Hello Again
- Message-ID: <8807011634.AA19536@chinet.UUCP>
- Date: 1 Jul 88 21:34:25 GMT
- Sender: allbery@ncoast.UUCP
- Reply-To: koala@uunet.uu.net@chinet.uucp
- Lines: 212
- Approved: allbery@ncoast.UUCP
-
- Posting-number: Volume 3, Issue 74
- Submitted-by: "A. Nonymous" <koala@uunet.uu.net@chinet.uucp>
- Archive-name: safe-rm
-
- As long as im submitting the other stuff, here is a simple prg that
- you can alias to rm.
-
- Instead of removing the file, it moves it to a directory in your home
- called .trash.
-
- It comes with a prg called 'rec' which simply does the opposite.
-
- It has all kinds of options. First is 'trash' then 'rec'.
-
- --
-
- Karl Meiser
- ..nucleus!{chinet,ddsw1,m-net}
-
- -------- trash
-
-
- #sccs "@(#)trash 1.5"
- #sccs "@(#)"
- #sccs "@(#)Tempoairly remove a file."
- #sccs "@(#)"
- #sccs "@(#)Copyright Karl Meiser 1988"
- #sccs "@(#)"
- #sccs "@(#)The following may be copied as long as no charge is given"
- #sccs "@(#)and the above notice stays intact"
- #sccs "@(#)"
- #sccs "@(#)I provide no warranty for its use nor am I liable for any
- #sccs "@(#)damages is causes."
- #sccs "@(#)"
- #sccs "@(#)Works only with ksh"
-
- if [ "$#" -eq 0 ]
- then
-
- print -
- print - "Usage: $0 [options] [files]"
- print -
- print - "Options: -k Remove Trashcan"
- print - " -l List Contents of Trashcan"
- print - " -r Remove entire directories"
- print - " -f Dont report errors"
- print -
- print - "Note that option -k will not work unless it is explicitlty used."
- print - "(Ie: $0 -k file will not work.)"
- print -
- print - "Note also that $0 -l file will work and will display a listing"
- print - "on that file (or files is wildcards are used) if it (they)"
- print - "are in your trashcan"
- print -
- print - "Files can be easily recoved using 'rec file(s)'. Wildcards are"
- print - "Supported, but must be quoted. (Ie: rec '_ab*')"
- print -
-
- exit
-
- fi
-
-
-
-
-
- if [ "$#" -eq 1 ]
- then
- case "$1" in
- -k*) print -n "Really remove ~/.trash: "
- read yn
-
- case "$yn" in
- y* |Y*) /bin/rm -fr ~/.trash ;;
- esac
-
- exit ;;
-
- -l*) cd ~/.trash
- shift
- eval dir $*
- exit ;;
- esac
- fi
- for x in $*
- do
-
- if [ "$x" = "-f" ]
- then
- err="n"
- else
- err="y"
- fi
-
- done
-
- if [ -d ~/.trash ]
- then :
- else
- if mkdir ~/.trash
- then :
- else
- if [ "$err" = "y" ]
- then
- print - "$0: Cant create ~/.trash"
- exit
- fi
- fi
- fi
-
- if [ "$1" = "-r" ]
- then
-
- shift
-
- for x in $*
- do
-
- if mv $x/* ~/.trash 2>/dev/null
- then :
- else
- if [ "$err" = "y" ]
- then
-
- print - "$0: Cant copy contents of directory $x"
-
- fi
- fi
-
- if rmdir $x 2>/dev/null
- then :
- else
- if [ "$err" = "y" ]
- then
-
- print - "$0: Cant Remove Directory $x"
-
- fi
- fi
- fi
-
- else
-
- for x in $*
- do
-
- if mv $x ~/.trash
- then :
- else
- if [ "$err" = "y" ]
- then
- print - "$0: Cant read $x"
- fi
- fi
-
- done
-
- fi
-
- -------- rec
-
-
- #sccs "@(#)rec 1.1"
- #sccs "@(#)"
- #sccs "@(#)Recover a file from Trashcan"
- #sccs "@(#)"
- #sccs "@(#)Copyright Karl Meiser 1988"
- #sccs "@(#)"
- #sccs "@(#)The following may be copied as long as no charge is given"
- #sccs "@(#)and the above notice stays intact"
- #sccs "@(#)"
- #sccs "@(#)I provide no warranty for its use nor am I liable for any
- #sccs "@(#)damages is causes."
- #sccs "@(#)"
- #sccs "@(#)Works only with ksh"
-
- if [ "$#" -eq 0 ]
- then
-
- print -
- print - "Usage: $0 [-f] file(s)"
- print -
- print - "The -f switch will cause errors to be suppressed"
- print -
- print - "This program will move files from the trashcan to the current"
- print - "Directory. Note that wildcards do work if quoted. (Ie:"
- print - "rec '_ab*' will work, but rec _ab* probally wont.)"
- print -
-
- exit
-
- fi
-
- cdir="$PWD"
-
- cd ~/.trash
-
- if [ "$1" = "-f" ]
- then
-
- shift
- mv $* $cdir 2>/dev/null
-
- else
-
- mv $* $cdir
-
- fi
-
- cd $cdir
-
- --------
-