(1)下载
[root@node0 ~]# wget https://launchpad.net/safe-rm/trunk/0.12/+download/safe-rm-0.12.tar.gz
(2)解压缩
[root@node0 ~]# tar -zxvf safe-rm-0.12.tar.gz -C /opt
safe-rm-0.12/
safe-rm-0.12/INSTALL
safe-rm-0.12/README
safe-rm-0.12/COPYING
safe-rm-0.12/safe-rm
safe-rm-0.12/Changes
[root@node0 ~]#
(3)查看INSTALL
[root@node0 ~]# cat /rooot/safe-rm-0.12/INSTALL
In order to install safe-rm and make sure that it is being picked up instead of
the usual "rm" command, make sure that you copy it in a location at the front of
your path.
For example, if your path contains:
PATH=/usr/local/bin:/usr/bin:/bin
Then, putting safe-rm in /usr/local/bin and renaming it to "rm" will ensure that
all users on your system use safe-rm instead of the real rm.
[root@node0 ~]#
(4)查看safe-rm,部分重要内容如下
my $GLOBAL_CONFIG_FILE = '/etc/safe-rm.conf';
my %default_protected_dirs = (
'/bin' => 1,
'/boot' => 1,
'/dev' => 1,
'/etc' => 1,
'/home' => 1,
'/initrd' => 1,
'/lib' => 1,
'/lib32' => 1,
'/lib64' => 1,
'/proc' => 1,
'/root' => 1,
'/sbin' => 1,
'/sys' => 1,
'/usr' => 1,
'/usr/bin' => 1,
'/usr/include' => 1,
'/usr/lib' => 1,
'/usr/local' => 1,
'/usr/local/bin' => 1,
'/usr/local/include' => 1,
'/usr/local/sbin' => 1,
'/usr/local/share' => 1,
'/usr/sbin' => 1,
'/usr/share' => 1,
'/usr/src' => 1,
'/var' => 1,
);
[root@node0 ~]# cp safe-rm-0.12/safe-rm /usr/local/bin/rm
[root@node0 ~]# chown root:root /usr/local/bin/rm
[root@node0 ~]# vi /etc/profile
export PATH=/usr/local/bin:/bin:/usr/bin:$PATH
[root@node0 ~]# source /etc/profile
添加测试目录
[root@node0 ~]# mkidr /1
[root@node0 ~]# mkidr /2
编辑配置文件
[root@node0 ~]# vi /etc/safe-rm.conf
[root@node0 ~]# cat /etc/safe-rm.conf
/1
/2
[root@node0 ~]#
删除测试
[root@node0 ~]# rm -rf /1
safe-rm: skipping /1
[root@node0 ~]# rm -rf /2
safe-rm: skipping /2
[root@node0 ~]#