如何避免命令 rm -rf 的悲剧
一、root高管用户为例,其他用户类同。
https://www.cnblogs.com/eos666/articles/10389179.html
[root@jenkins /]# vim /root/.bashrc
# .bashrc # User specific aliases and functions # alias rm='rm -i' # 修改成 alias rm='pwd && \ read -p "Are you sure?" y && [ $y == "y" ] && \ read -p "Are you sure?" y && [ $y == "y" ] && \ read -p "Are you sure?" y && [ $y == "y" ] && \ rm -i' alias cp='cp -i' alias mv='mv -i' # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi
source /root/.barshrc
二、测试
[root@jenkins /]# pwd
/
示例一
[root@jenkins /]# rm -rf *
/
Are you sure?n
示例二
[root@jenkins /]# rm -rf *
/
Are you sure?y
Are you sure?n
示例三
[root@jenkins /]# rm -rf /*
/
Are you sure?y
Are you sure?y
Are you sure?n
示例四
[root@jenkins /]# rm -rf /*
/
Are you sure?y
Are you sure?y
Are you sure?y
三、结果
示例一、二、三,不会删除根目录下的目录及文件。
示例四,3次确认后会直接把根目录下的所有目录及文件都删除掉,出大事了。
在 /tmp 目录下的测试,看截图: