定義rm命令別名shell
vim /etc/bashrc alias rm='/bin/rm.sh'
配置回收站腳本vim
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
配置回收站清空週期bash
#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