前言
搞过运维想过行业的淫们都有过rm之伤,造成血的教训。为了避免以后才出现类似的情况,强烈建议生产环境中千万不要使用rm -rf 这种操作,太危险了。为什么不学学Ubuntu/MacOS等系统有一个回收站,删除了可以去回收站里面找。经过折腾一番,终于找到了一个工具 trash-cli。
trash-cli是一个使用 python 开发的软件包,trash-cli trashes记录原始路径,删除日期和权限的文件。它使用KDE,GNOME和XFCE使用的相同垃圾桶,但您可以从命令行(和脚本)调用它。包含:
1  | * trash-put trash files and directories.  | 
trash-cli 安装
The easy way
Requirements:
Python 2.7 or Python 3
setuptools (use apt-get install python-setuptools on Debian)
Installation command:
1  | easy_install trash-cli  | 
From sources
System-wide installation:
1  | git clone https://github.com/andreafrancia/trash-cli.git  | 
User-only installation:
1  | git clone https://github.com/andreafrancia/trash-cli.git  | 
trash-cli 命令
查看安装成功之后的命令
1  | # ll /usr/bin/ | grep trash  | 
功能说明:
- trash-put 将文件或目录移入回收站
 - trash-empty 清空回收站
 - trash-list 列出回收站中的文件
 - trash-restore 还原回收站中的文件
 - trash-rm 删除回首站中的单个文件
 
用它替代 rm命令
1  | # vim .bashrc  | 
实验测试
删除测试:
1  | # rm -rf dump.sql  | 
还原删除的文件
1  | # trash-restore /root/dump.rdb  |