标签为 rm 的文章

给rm命令加上回收站功能

背景:
在群里,总会有人聊到曾经做过的最坑的事情,其中当然少不了rm命令,比如最出名的rm -rf /*命令。
受HDFS回收站机制的启发,我即兴的写了一个shell脚本来实现类似的功能。

具体配置:
[dong@localhost ~]$ sudo touch /usr/bin/delete
[dong@localhost ~]$ sudo chmod +x /usr/bin/delete
[dong@localhost ~]$ sudo vim /usr/bin/delete

[dong@localhost ~]$ mkdir tmp
[dong@localhost ~]$ cd tmp
[dong@localhost tmp]$ mkdir 1 2 3
[dong@localhost tmp]$ echo 1 > 1/1.txt
[dong@localhost tmp]$ echo 2 > 2/2.txt
[dong@localhost tmp]$ echo 3 > 3/3.txt
[dong@localhost tmp]$ touch a b c
[dong@localhost tmp]$ ln -s a d
[dong@localhost tmp]$ delete 1

Move 1 to /home/dong/.Trash/20160415114210/home/dong/tmp/1? [y/n] y
Moved 1 to /home/dong/.Trash/20160415114210/home/dong/tmp/1

[dong@localhost tmp]$ delete -f *

Moved 2 to /home/dong/.Trash/20160415114217/home/dong/tmp/2
Moved 3 to /home/dong/.Trash/20160415114217/home/dong/tmp/3
Moved a to /home/dong/.Trash/20160415114217/home/dong/tmp/a
Moved b to /home/dong/.Trash/20160415114217/home/dong/tmp/b
Moved c to /home/dong/.Trash/20160415114217/home/dong/tmp/c
Moved d to /home/dong/.Trash/20160415114217/home/dong/tmp/d

,

No Comments