上一章节,讲了自己悲剧的删库事件。
原因总结:
(1)手贱
(2)还是手贱
(3)不过大脑
(4)Linux没有回收站功能


俗话说,吃一堑长一智。接下来就是我的解决方案。
给Linux添加一个回收站的功能,这是不是很高大上啊
这下就不怕手贱删库了

删除是危险系数很高的操作,一旦误删可能会造成难以估计的损失。
在 Linux 系统中这种危险尤为明显,一条简单的语句:rm –rf /* 就会把整个系统全部删除,而 Linux 并不会因为这条语句的不合理而拒绝执行。

这时,有个像Windows的那样的回收站是多么的重要啊。下面可以使用代码实现

rm命令修改
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
vim /etc/bashrc
alias rm=delete #命令别名,通过delete来实现rm改为mv
alias r=delete
alias rl='ls /trash' #rl 命令显示回收站中的文件
alias ur=undelfile #ur 命令找回回收站的文件
undelfile()
{
mv /trash/$@ ./
}
delete()
{
if [ ! -d "/trash/" ];then
mkdir /trash
fi
\mv --backup=numbered $@ /trash/
}
cleartrash()
{
read -p "clear sure?[n]" confirm
[ $confirm == 'y' ] || [ $confirm == 'Y' ] && /bin/rm -rf /trash/*
}
|
添加完毕后保存,执行source命令生效

使用方法
以使用rm(删除),ur(撤销),rl(列出回收站),cleartrash(清空回收站)命令了。
删除一个文件夹,hellworld下面的文件均被移到回收站中
1
|
rm helloworld/ 或者 r helloworld/ 或者 delete helloworld/
|
删除一个文件
1
|
rm 123.txt 或者 r 123.txt 或者 delete 123.txt
|

列出回收站信息

要查看回收站内容详细信息,只要加个参数就好

撤销123.txt
1
|
ur 123.txt 或者 undelfile 123.txt
|
撤销helloworld文件夹
1
|
ur helloworld 或者 undelfile helloworld
|

清空回收站
1
2
3
|
[root@Master ~]# cleartrash #会弹出是否清空
clear sure?[n]y
[root@Master ~]#
|
删库,我害怕删库吗
