使用mv命令代替 rm命令,将文件移动到一个垃圾箱文件夹中,并记录删除日志。

PARA_CNT=$#
TRASH_DIR="/main/.rm_trash/files" for i in $*; do
if [[ "$i" == "-rf" ]];then
continue
elif [[ "$i" == "-r" ]];then
continue
fi
#echo "参数 $i"
STAMP=`date -d today +"%Y-%m-%d-%T"`
fileName=`basename $i`
first_char="${i:0:1}"
#echo $first_char
if [[ "$first_char" == "/" ]];then
echo "["$STAMP"] del from "$i >> $TRASH_DIR/../rm.log
else
echo "["$STAMP"] del from "`pwd`"/"$i >> $TRASH_DIR/../rm.log
fi
mv $i $TRASH_DIR/$fileName.$STAMP
done

/etc/bash.bashrc中添加如下语句:

alias rm="bash /main/.rm_trash/rm.sh"
05-29 00:23