#!/bin/bash
#:set ff=unix
#:set nobomb
#-*- coding:utf-8 -*-
######################################################################
## Filename: Trash.py
##
## Copyright (C) 2014.6
## Author: [email protected]@qq.com
##
## 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/"\[email protected]" ./
}
trash()
{
mv "\[email protected]" /root/.trash/
}" >>/root/.bash_profile
source /root/.bash_profile #source该文件,生效了
fi
#删除后的文件就在/root/.trash里
来源:http://iotos.iteye.com/blog/2092948
Linux 防止rm -rf 误删Shell脚本