How to recover (and remove) UNIX files
Jeff Medcalf
jeffm at uokmax.UUCP
Wed Aug 23 09:41:56 AEST 1989
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 at uokmax.UUCP (Brad Knowles)
and were modified by jeffm at uokmax.UUCP (Jeff Medcalf). rmclean was created by
jeffm at 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 at 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 at uokmax.UUCP Jeff Medcalf jeffm at uokmax.ecn.uoknor.edu
Is she spoiled?
No, she always smells that way.
More information about the Comp.unix.questions
mailing list