重写rm命令 replease rm to trash 必须使用root编辑/etc/bashrc
vim /etc/bashrc
在最后面增加如下脚本
1 saferm () 2 { 3 if [ ! -d /export/dustbin ] 4 then 5 mkdir -p /export/dustbin 6 chmod 777 /export/dustbin 7 if [ $? -ne 0 ] 8 then 9 echo "Error: failed to create /export/dustbin" 10 fi 11 fi 12 local dst=`mktemp -d -p /export/dustbin` 13 local arg=`echo $* | sed "s/(^-w+)|(s-w+)/ /g"` 14 mv ${arg} ${dst} 15 } 16 alias rm='saferm'
所有用户在调用bash时候都会先加载该文件/etc/bashrc,也可以写入在单个用户的家目录下面的.bashrc文件中,针对单个用户做限制。
如果确认需要删除数据文件可以使用/bin/rm绝对路径进行删除