47 lines
1.1 KiB
Bash
Executable File
47 lines
1.1 KiB
Bash
Executable File
#!/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
|