[comp.unix.questions] How to recover

jeffm@uokmax.UUCP (Jeff Medcalf) (08/23/89)

The following shell scripts are:

	rm -- remove files to compressed storage in /usr/tmp/.$USER
	unrm -- bring those files back
	rml -- list files "removed"
	rmclean -- clean up /usr/tmp/.$USER

rm, unrm, and rml were originally created by blknowle@uokmax.UUCP (Brad Knowles)
and were modified by jeffm@uokmax.UUCP (Jeff Medcalf).  rmclean was created by
jeffm@uokmax.UUCP.


#! /bin/sh
#This is rm.  It moves files to be removed to /usr/tmp/.$USER, then compresses
#them.  If /usr/tmp/.$USER does not exist, it will be created.  The -f option
#forces removal to be permanent.
#
name="rm"
sd="/usr/tmp/.$USER"
if test $# -lt 1
then echo "Usage: $name [-f] <filename> [<filenames>]" >&2
     exit 1
elif test "$1" = "-f"
then shift
    /bin/rm $* &
    exit 0
elif test ! -s $sd
then mkdir $sd
     chmod 700 $sd
fi
until test $# -eq 0
do
    if test ! -f $1
    then echo "$name: $1: not normal or nonexistent file." >&2
    else (/bin/cp $1 $sd ; /usr/local/compress $sd/$1 > /dev/null 2>&1 ; /bin/rm -f $1) &
    fi
    shift
done
exit 0
#END OF RM



#This is rml.  It simply displays files which were previously rm'd.
#This is better as an alias.
ls -lasig /usr/tmp/."$USER"| less
#END OF RML


#! /bin/sh
#This is unrm.  It will recover files previously rm'd.
name="unrm"
sd="/usr/tmp/.$USER"
if test $# -lt 1
then echo "Usage: $name <filename> [<filenames>]" >&2
     exit 1
fi
until test $# -eq 0
do
    if test -s $sd/$1.Z 
    then exist=2
    else exist=0
    fi
    if test -s $sd/$1 
    then exist=`expr $exist + 1`
    fi
    if test -f $sd/$1.Z 
    then normal=2
    else normal=0
    fi
    if test -f $sd/$1 
    then normal=`expr $normal + 1`
    fi
    if test $exist -eq 0 -o $normal -eq 0
	then echo "$name: $1: not normal or nonexistent file." >&2
    elif test $exist -eq 2 -a $normal -eq 2
	then (/usr/local/uncompress $sd/$1 > /dev/null 2>&1 ; /bin/cp $sd/$1 . ; /bin/rm $sd/$1) &
    elif test $exist -eq 1 -a $normal -eq 1
	then /bin/cp $sd/$1 .
	/bin/rm $sd/$1
    elif test $exist -eq 3 -o $normal -eq 3
	then echo "$name: cannot uncompress $1.Z because $1 already exists." >&2
	/bin/cp $sd/$1.Z .
	/bin/rm $sd/$1
	/bin/rm $sd/$1.Z
    else echo "$name: Something TRULY bizzarre has happened.  Report to jkmedcal@uokmax." >&2
	echo "argv[1] = $1, exist = $exist, normal = $normal" >&2
	exit 3
    fi
    shift
done
exit 0
#END OF UNRM


#! /bin/sh
#Permanently remove a file from /usr/tmp/.$USER
#The -z option looks for files with a .Z suffix
#The -all option completely removes the directory.
name="rmclean"
sd="/usr/tmp/.$USER"
if test $# -lt 1
then
echo "$name: usage: rmclean [-z | -all] filename [filenames]"
elif test ! -s $sd
then echo "$name: Directory $sd does not exist."
exit 1
fi
if test "$1" = "-z"
then
  isz=".Z"
  shift
else
  isz=""
fi
if test "$1" = "-all"
  then /bin/rm -r $sd
  echo "$sd is cleaned."
  exit 0
else
until test $# -eq 0
do
  if test -f $sd/$1$isz
    then /bin/rm -f $sd/$1$isz
  else echo "$name: File $sd/$1$isz does not exist."
    exit 1
  fi
shift
done
exit 0
fi
jeffm@uokmax.UUCP	Jeff Medcalf	jeffm@uokmax.ecn.uoknor.edu

Is she spoiled?
No, she always smells that way.

apippin@polyslo.CalPoly.EDU (Pinhead@Spikes.slo.ca.EDU) (08/25/89)

jeffm@uokmax.UUCP (Jeff Medcalf) writes:

~The following shell scripts are:
~	rm -- remove files to compressed storage in /usr/tmp/.$USER
~	unrm -- bring those files back
~	rml -- list files "removed"
~	rmclean -- clean up /usr/tmp/.$USER

	[Scripts deleted.]

Instead of using shell scripts, here is a way of accomplishing the same thing
using 'alias':

rm:  To move a file into a predefined directory.
     alias rm    '\mv \!* ~/.trash'

del:  To REALLY delete a file (use sparingly!)
     alias del   '\rm'

grab:  To place a copy of the deleted file into the current directory.
     alias grab  'cp ~/.trash/\!* .'

show:  List files in 'delete directory'.
     alias show  'ls -sAF ~/.trash' 

empty:  To clean out files in 'delete directory'
     alias empty '\rm -r ~/.trash/* >& /dev/null; \rm ~/.trash/.* >& /dev/null'

It does not compress the files, and a directory must be present (I have mine
called '~/.trash')

~jeffm@uokmax.UUCP	Jeff Medcalf	jeffm@uokmax.ecn.uoknor.edu

a.
-- 
Andy Pippin                    "Do you think God gets stoned?  Look at the
apippin@polyslo.CalPoly.EDU       platypus... I think so." - R. Williams

limes@sun.com (Greg Limes) (08/26/89)

Gee, this comes up every so often.

May I make the suggestion that you use "rm" for the "really remove
the damn thing" command, and "del" for "do it safely"? Now, if you
by chance end up in the wrong environment, you do not end up using
the wrong command ...
--
-- Greg Limes	limes@sun.com	...!sun!limes	73327,2473	[choose one]