-
1
- #1
theotyflos
Programmer
I hope this script will be usefull. It saved my work a lot of times. It works on Sco Openserver 5.0.x, ksh. Put it in your .profile.
:
:
:
:
Code:
SafeDelete() {
F_OPT=""
I_OPT=""
R_OPT=""
USAGE="usage: rm [-firR] file..."
while getopts firR CHR # Get options from command line
do
case $CHR in
f) F_OPT=-f ;;
i) I_OPT=-i ;;
r|R) R_OPT=-r ;;
*) echo $USAGE
exit 1 ;;
esac
done
shift `expr $OPTIND - 1`
if [ $# = 0 ]; then
echo $USAGE
exit 1
else
T=`date +%d_%m_%Y_%T` # Extension suffixed to deleted files
for F in $*
do
if [ -e $F ]; then
D=$(cd `dirname $F`; pwd -P) # Get file's Directory
case $D in # and check if it is the trashcan
~/.trashcan*) REAL_RM=true ;;
*) REAL_RM=false ;;
esac
if [ "$REAL_RM" = "true" ]; then # If in trashcan a real delete...
\rm $F_OPT $I_OPT $R_OPT $F
else # ...else a safe delete
if [ "$D" != "/" ]; then
mkdir -p ~/.trashcan$D 2>/dev/null
fi
BF=`basename $F`
mv $F_OPT $I_OPT $F ~/.trashcan$D/${BF}_$T
fi
else
echo "rm: $F non-existent"
fi
done
fi
}
:
Code:
alias rm="SafeDelete"
: