标签:ras ble The name move file hat 用户 done
定义rm命令别名vim /etc/bashrc
alias rm=‘/bin/rm.sh‘
配置回收站脚本
vim /bin/rm.sh
#!/bin/bash
trash=/tmp/recycle_tmp
[ -d ${trash} ] || mkdir -m 777 -p ${trash}
Dir=`pwd`
now=`date +%Y%m%d%H%M%S`
if [ "$Dir" != "$trash" ]
then
for dir in $@
do
[ "${dir}" = "-f" ]&&continue
[ "${dir}" = "-r" ]&&continue
[ "${dir}" = "-fr" ]&&continue
[ "${dir}" = "-rf" ]&&continue
file_path=`dirname ${dir}`
file_name=`basename ${dir}`
cd ${file_path} && mv ${file_name} /tmp/recycle_tmp/${file_name}_${now}
done
else
read -p "Remove or empty trashs ?(y/n)" isok
case $isok in
Y|y)
/bin/rm -rf $@
;;
N|n)
echo "Operate canceled."
;;
*)
echo "input Y|y clear trash Directory. or N|n no operation."
;;
esac
fi
chmod 755 /bin/rm.sh
配置回收站清空周期
#Ansible: Cycle recycle_tmp clean ## 放置在root用户crontab下
1 0 */2 * * /bin/bash /data1/workshell/auto_rm.sh > /dev/null 2>&1
vim /data1/workshell/auto_rm.sh
#!/bin/bash
chattr -a /tmp/recycle_tmp
/bin/echo y|/bin/rm -rf /tmp/recycle_tmp/*
chattr +a /tmp/recycle_tmp
chmod 700 /data1/workshell/auto_rm.sh
标签:ras ble The name move file hat 用户 done
原文地址:https://blog.51cto.com/swiki/2493022