linux防误删shell脚本
#!/bin/bash
TRASH_DIR="/home/.trash"
[ ! -d $TRASH_DIR ] && mkdir $TRASH_DIR
move_ops(){
for i in $*
do
[ $i == "-rf" ] && continue
[ $i == "-f" ] && continue
[ ! -e $i ] && echo -e "$i 文件不存在" && continue
STAMP=`date +%Y%m%d%H%M`
USER=`whoami`
fileName=`basename $i`
bak_file_name="${TRASH_DIR}/BAK_${fileName}.${STAMP}"
mv $i ${bak_file_name} >> /dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\t$USER $STAMP $i已删除!(在回收站中查看:${bak_file_name})"
else
echo -e "\t$USER $STAMP $i无法删除!请检查$i文件是否存在或者其他原因"
fi
done
}