Files
StateGrid/install_shell/set_recycling-station.sh
Qin Bo 2235771f09 Initial commit
Signed-off-by: Qin Bo <bqin@linx-info.com>
2014-02-19 09:07:55 +08:00

47 lines
1.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
#set_recycling-station.sh
#Linux回收站改写rm防止误删文件引起无法恢复
#Jincheng Ye
#2013/05/14
#modified by Jincheng Ye,2013/10/28
grep trash /root/.bashrc &> /dev/null
if [ $? -eq 0 ];then
echo "trash exist..."
else
cat >> /root/.bashrc <<EOF
#Linux回收站改写rm,防止bash用户误删文件引起无法恢复
mkdir -p ~/.trash
alias rm=trash
alias r=trash
alias rl='ls ~/.trash'
alias ur=undelfile
#回收函数
undelfile()
{
mv -i ~/.trash/\$@ ./
}
#垃圾函数,该函数不删除系统重要目录下的重要文件如果用户实在想删除可以指定rm命令的路径来完成原来rm的功能如:
#/bin/rm /opt/test.sh
trash()
{
#Can't delete / /s* /b* /l* /d* /e* /u* /r* /v* /h* /o* /p* /* ~ ~/*
if [[ \$@ != /[sbldeurvhop]* ]] && [[ \$@ != "/" ]] && [[ \$@ != "/*" ]] && [[ \$@ != ~* ]]
then
mv \$@ ~/.trash/
else
echo "Can't delete \$@!"
fi
}
#清除垃圾回收站的内容的函数
cleartrash()
{
read -p "clear sure?[y/n]" confirm
[ ${confirm} == 'y' ]||[ ${confirm} == 'Y' ] && /bin/rm -rf ~/.trash/*
}
EOF
fi