Linux 防止rm -rf 误删Shell脚本

#!/bin/bash
#:set ff=unix
#:set nobomb
#-*- coding:utf-8 -*-
######################################################################
## Filename:     Trash.py
##                
## Copyright (C) 2014.6
## Author:        TangMeiHao@[email protected]
##               
## Description:   Shell防止rm -rf 误删
##                
######################################################################
cat /root/.bash_profile | grep "trash" &>/dev/null
if [ $? -eq 0 ]#通过if语句判断,是否已经执行过这个脚本了,不然的话执行一次,就追加一次该内容
then
	echo "HAS BE DONE"
else
	echo  -e  "
		mkdir -p ~/.trash
		alias rm=trash
		alias r=trash
		alias rl='ls ~/.trash'
		alias ur=undelfile
		function undelfile()
		{
			mv -i ~/.trash/"\$@" ./
	
		}	

		trash()
		{
			mv  "\$@"  /root/.trash/
		}" >>/root/.bash_profile

	source /root/.bash_profile #source该文件,生效了
fi

#删除后的文件就在/root/.trash里

#哈哈,很少写博客玩,有错误欢迎指正














猜你喜欢

转载自iotos.iteye.com/blog/2092948