一. 添加脚本: [root@qll251 ~]# vim /bin/delete 1 #! /bin/bash 2 [ ! -d /.recycle ] && mkdir -v /.recycle && chmod 777 /.recycle 3 4 if [ $# -eq 0 ]; then 5 echo "Usage: delete file1 [file2 file3...]" && exit 6 6 fi 7 8 read -p "Are you sure you want to delete it? [Y/N]: " action 9 case $action in 10 y) ;; 11 Y) ;; 12 *) exit 13 esac 14 15 for file in $@; do 16 now=date +%Y-%m-%d-%H:%M:%S 17 newfile=basename $file 18 mv $file /.recycle/$newfile.$now && echo "$file is deleted!" 19 done 二. 修改别名

编辑~/.bashrc文件,增加一行

alias rm='sh /bin/delete'

添加可执行权限:

[root@qll251 ~]# chmod +x /bin/delete

三. 定时清空

执行crontab -e,设置每周执行清空回收站动作

0 0 * * 0 rm -rf /.recycle