Linux safe-rm替换rm命令

#!/bin/bash
# -*- coding: UTF-8 -*-
# Filename: safe-rm.sh
# Description: safe-rm替换rm,在自己的虚拟机上手误,执行错了命令,悲剧......
# Author: SERE
# 以下是修改rm命令的具体操作...
cd /tmp
wget https://launchpad.net/safe-rm/trunk/0.12/+download/safe-rm-0.12.tar.gz &> /dev/null
tar -zxf safe-rm-0.12.tar.gz &> /dev/null
cd safe-rm-0.12/
cp -f safe-rm /usr/local/bin/
ln -sf /usr/local/bin/safe-rm /usr/local/bin/rm
sed -i '$a\export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:$PATH' /etc/profile
source /etc/profile
ls -l / | awk -F " " '{print "/"$9"/""*"}' >/etc/safe-rm.conf
sed -i 's/\/\//\//g' /etc/safe-rm.conf
sed -i '1i\/' /etc/safe-rm.conf
sed -i 's/\/tmp\/\*/\/tmp/' /etc/safe-rm.conf
sed -i '/my @allowed_args = ();/i\my @mylist = ("/bin","/lib","/lib64","/sbin");' /usr/local/bin/rm
sed -i '/my $pathname = $_;/a\\tforeach $a (@mylist){\n\tif ( $pathname eq $a) {\n\t\tprint ("warning: what the hell are you thinking about?\\n");\n\t\texit;\n\t\t}\n\t}' /usr/local/bin/rm
sed -i '103s/^/#/' /usr/local/bin/rm
sed -i '103a\\tprint ("warning: what do you want to do?\\n");\n \texit;' /usr/local/bin/rm
echo -e "\033[32mThe safe-rm configuration is complete.\033[0m"

你可能感兴趣的:(Safety)