文章参考:https://www.linuxprobe.com/rm-saferm-trash.html 文章参考:https://www.cnblogs.com/kerrycode/p/12931844.html
- 安装脚本
下载地址
git clone https://github.com/lagerspetz/linux-stuff
curl -O http://8.210.62.122/Linux/stuff/linux-stuff-master.zip
- 解压
unzip linux-stuff-master.zip
- 把脚本放到/bin目录下
mv linux-stuff-master/scripts/saferm.sh /bin
rm -rf linux-stuff-master
- 配置环境变量(单个用户)
cat /root/.bashrc
alias rm=saferm.sh
alias cp='cp -i'
alias mv='mv -i'
source /root/.bashrc
测试
[root@localhost ~]
[root@localhost ~]
Moving 123.txt to /root/Trash
- 配置全局环境变量
[root@localhost ~]
fi
alias rm=saferm.sh
source /etc/bashrc
测试
[root@localhost ~]
[root@localhost ~]
[ying@localhost ~]$ pwd
/home/ying
echo "ying" >ying.txt
[ying@localhost ~]$ rm -rf ying.txt
Moving ying.txt to /home/ying/Trash
当不想放在~/Trash目录时
[ying@localhost ~]$ echo "test" > test.txt
[ying@localhost ~]$ pwd
/home/ying
[ying@localhost ~]$ ls Trash/
ying.txt
[ying@localhost ~]$ \rm -rf Trash/ying.txt
[ying@localhost ~]$ ls Trash/
- 定时清理~/Trash目录下的文件
脚本地址
[root@localhost scripts]
cat > home_list.txt << EOF
/root
/home/ying
EOF
while read line
do
find $line/Trash/ -mtime 7 -iname "*" -exec rm -rf {} \;
done < home_list.txt
0 2 * * * /bin/bash /data/scripts/clean_Trash.sh
|