使用trash-cli防止rm -rf 误删除带来的灾难(“事前”非“事后”)
trash-cli是一个使用 python 开发的软件包,包含 trash-put、restore-trash、trash-list、trash-empty、trash-rm等命令,我们可以通过这写命令,将文件移动到回收站,或者还原删除了的文件。
trash-cli的项目地址:trash-cli下载地址
转载于http://www.seiang.com/?p=229
1、下载trash-cli安装包
- [root@VM_54_118_centos others]# git clone https://github.com/andreafrancia/trash-cli.git
- Cloning into 'trash-cli'...
- remote: Enumerating objects: 4556, done.
- remote: Total 4556 (delta 0), reused 0 (delta 0), pack-reused 4556
- Receiving objects: 100% (4556/4556), 1.17 MiB | 716.00 KiB/s, done.
- Resolving deltas: 100% (2791/2791), done.
- 进入下载目录
- [root@VM_54_118_centos others]# cd trash-cli/
- [root@VM_54_118_centos trash-cli]# ll
- total 112
- -rw-r--r-- 1 root root 251 Feb 2 17:29 bugs.txt
- -rw-r--r-- 1 root root 4766 Feb 2 17:29 check_release_installation.py
- -rw-r--r-- 1 root root 17992 Feb 2 17:29 COPYING
- -rw-r--r-- 1 root root 1432 Feb 2 17:29 CREDITS.txt
- drwxr-xr-x 3 root root 4096 Feb 2 17:29 docs
- -rw-r--r-- 1 root root 782 Feb 2 17:29 DONE.txt
- -rw-r--r-- 1 root root 3408 Feb 2 17:29 HISTORY.txt
- -rwxr-xr-x 1 root root 240 Feb 2 17:29 install-rpm.sh
- drwxr-xr-x 2 root root 4096 Feb 2 17:29 integration_tests
- drwxr-xr-x 3 root root 4096 Feb 2 17:29 man
- -rw-r--r-- 1 root root 78 Feb 2 17:29 MANIFEST.in
- -rw-r--r-- 1 root root 4774 Feb 2 17:29 README.rst
- -rw-r--r-- 1 root root 24 Feb 2 17:29 requirements-dev.txt
- -rwxr-xr-x 1 root root 293 Feb 2 17:29 setup.cfg
- -rw-r--r-- 1 root root 2423 Feb 2 17:29 setup.py
- drwxr-xr-x 2 root root 4096 Feb 2 17:29 tasks
- -rw-r--r-- 1 root root 799 Feb 2 17:29 TODO.txt
- drwxr-xr-x 2 root root 4096 Feb 2 17:29 trashcli
- -rwxr-xr-x 1 root root 127 Feb 2 17:29 trash-put
- -rwxr-xr-x 1 root root 126 Feb 2 17:29 trash-rm
- drwxr-xr-x 2 root root 4096 Feb 2 17:29 unit_tests
- -rw-r--r-- 1 root root 243 Feb 2 17:29 Vagrantfile
2、开始安装
- [root@VM_54_118_centos trash-cli]# python setup.py install
- .......
- running install_scripts
- copying build/scripts-2.7/trash-rm -> /usr/bin
- copying build/scripts-2.7/trash-list -> /usr/bin
- copying build/scripts-2.7/trash-put -> /usr/bin
- copying build/scripts-2.7/trash-empty -> /usr/bin
- copying build/scripts-2.7/trash -> /usr/bin
- copying build/scripts-2.7/trash-restore -> /usr/bin
- changing mode of /usr/bin/trash-rm to 755
- changing mode of /usr/bin/trash-list to 755
- changing mode of /usr/bin/trash-put to 755
- changing mode of /usr/bin/trash-empty to 755
- changing mode of /usr/bin/trash to 755
- changing mode of /usr/bin/trash-restore to 755
- running install_data
- copying man/man1/trash-empty.1 -> /usr/share/man/man1
- copying man/man1/trash-list.1 -> /usr/share/man/man1
- copying man/man1/trash-restore.1 -> /usr/share/man/man1
- copying man/man1/trash-put.1 -> /usr/share/man/man1
- copying man/man1/trash-rm.1 -> /usr/share/man/man1
- running install_egg_info
- Writing /usr/lib/python2.7/site-packages/trash_cli-0.17.1.14-py2.7.egg-info
3、安装成功后我们的系统就有了以下工具.
- [root@VM_54_118_centos ~]# ll /usr/bin/ | grep trash
- -rwxr-xr-x 1 root root 123 Feb 2 17:43 trash
- -rwxr-xr-x 1 root root 125 Feb 2 17:43 trash-empty
- -rwxr-xr-x 1 root root 124 Feb 2 17:43 trash-list
- -rwxr-xr-x 1 root root 123 Feb 2 17:43 trash-put
- -rwxr-xr-x 1 root root 127 Feb 2 17:43 trash-restore
- -rwxr-xr-x 1 root root 122 Feb 2 17:43 trash-rm
功能说明:
trash-put 将文件或目录移入回收站
trash-empty 清空回收站
trash-list 列出回收站中的文件
trash-restore还原回收站中的文件
trash-rm 删除回首站中的单个文件
4、安装完毕之后我们可以通过一些配置,用它替代 rm命令
- [root@VM_54_118_centos ~]# vim .bashrc
- # .bashrc
- #alias rm='rm -i'
- alias rm='trash-put'
5、实验测试
删除测试:
- [root@VM_54_118_centos ~]# rm -rf dump.rdb
- [root@VM_54_118_centos ~]# ll ~/.local/share/Trash/files
- -rw-r--r-- 1 root root 123 Jul 17 2018 dump.rdb
- [root@VM_54_118_centos ~]# trash-list
- 2019-02-02 18:02:33 /root/dump.rdb
还原删除的文件
- [root@VM_54_118_centos ~]# trash-restore /root/dump.rdb
- 0 2019-02-02 18:01:08 /root/dump.rdb.bak
- 1 2019-02-02 18:02:33 /root/dump.rdb
- What file to restore [0..1]: 1
- 还原成功
- [root@VM_54_118_centos ~]# ll /root/dump.rdb
- -rw-r--r-- 1 root root 123 Jul 17 2018 /root/dump.rdb
备注:
trash-put命令会把我们想要删除的文件移动到~/.local/share/Trash/files 中。
相关信息记录在~/.local/share/Trash/info中。
使用trash-cli防止rm -rf 误删除带来的灾难(“事前”非“事后”)的更多相关文章
- 高性能Linux服务器 第6章 ext3文件系统反删除利器ext3grep extundelete工具恢复rm -rf 误删除的文件
高性能Linux服务器 第6章 ext3文件系统反删除利器ext3grep extundelete工具恢复rm -rf 误删除的文件 只能用于ext3文件系统!!!!!!!高俊峰(高性能Linux ...
- [rm] Linux 防止"rm -rf /" 误删除
一.缘由: 最近看到这则新闻,很是悲伤,因为我最近也在用ansible:然而这一错误源自Ansible上糟糕的代码设计,这款Linux实用工具被用于在多台不同服务器上自动执行脚本. 开发者解释到,实际 ...
- Linux防止“rm -rf /”误删除
说明:不解释了,运维应该在每台服务器都去配置这个问题以减少灾难的发生 方法: 1.safe-rm safe-rm是一个开源软件用来替代不太安全的rm,可以在/etc/safe-rm.conf中配置路径 ...
- 使用 trash 避免 rm -rf 悲剧
昨晚做了一个令人痛心疾首的操作,rm -rf something,把我个人电脑里的重要文件夹给删掉了,懵逼了半天才缓过来.还好是个人文件,不对公司造成影响.这件事也让我意识到 rm -rf 确实是个高 ...
- 用extundelete恢复rm -rf删的文件
“慎用rm -rf命令,除非你知道此命令带来的后果.”这是一条Linux用户守则,虽然大多数用户都明白这条语句的含义,但是我觉得还需要完善一下,为这条语句加 上一个使用前提:在你确认自己拥有清醒头脑, ...
- 慎用rm -rf
首先,搞个回收站在~下 .bashrc或者.bash_profile加入 mkdir -p ~/.trash alias rm=trash alias r=trash alias rl='ls ~/. ...
- 使用 trash-cli 逃出 rm 命令误删除重要文件的阴影
今天是一个难忘的日子,当时本来想清除我们公司网站cms目录下面一些cdn推送网页后残留的垃圾文件,结果在执行rm -rf conten* 时打成了rm -rf conten *结果就悲剧了.cms目录 ...
- Linux 中如何避免 rm -rf /*
Linux 的删除命令中 rm中没有回收站的概念,一旦文件被删除比较难还原.更可怕的是rm -rf /*,连自己都能删 这命令太危险了,弄错了就核爆了,带来的损失的巨大的.比如 Gitlab.com ...
- [sh]rm -rf*的防护和普通用户执行命令
尽量用普通用户执行,因为普通用户无法删除root的文件,避免误删除 rm -rf 不可取, 尽量find+rm -rf 尽量cd && rm -rf * 加上逻辑 cd /tmp/re ...
随机推荐
- JS--操作DOM树
<ul id="ul1"> <li id="li1">111</li> <li id="li2"& ...
- FFmpeg 将YUV数据转RGB
只要开始初始化一次,结束后释放就好,中间可以循环转码 AVFrame *m_pFrameRGB,*m_pFrameYUV; uint8_t *m_rgbBuffer,*m_yuvBuffer; str ...
- Spring MVC 使用介绍(三)—— Controller接口控制器
一.概述 Controller接口类图如下,其中,BaseCommandController已从Spring 4移除 基于继承Controller接口的方式已经不推荐使用,仅供学习参考 二.基于Con ...
- BZOJ4317Atm的树&BZOJ2051A Problem For Fun&BZOJ2117[2010国家集训队]Crash的旅游计划——二分答案+动态点分治(点分树套线段树/点分树+vector)
题目描述 Atm有一段时间在虐qtree的题目,于是,他满脑子都是tree,tree,tree…… 于是,一天晚上他梦到自己被关在了一个有根树中,每条路径都有边权,一个神秘的声音告诉他,每个点到其他的 ...
- POJ1860-Currency Exchange-判正环
两种货币的交换可以当成两条边,建图后跑Bellman_ford算法就好了. Bellman_ford算法可以用来处理负边权,所以可以判断是否存在负环.反过来就可以判断是否存在正环. /*------- ...
- Python中的urllib2模块解析
Name urllib2 - An extensible library for opening URLs using a variety of protocols 1. Description Th ...
- Tarjan求强连通分量,缩点,割点
Tarjan算法是由美国著名计算机专家发明的,其主要特点就是可以求强连通分量和缩点·割点. 而强联通分量便是在一个图中如果有一个子图,且这个子图中所有的点都可以相互到达,这个子图便是一个强连通分量,并 ...
- bzoj 1015: [JSOI2008]星球大战starwar (逆向思维+并查集)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1015 思路: 题目是要我们对当前图拆掉k个点,问,每拆一个点后图中有多少个联通块,我们可以逆 ...
- bzoj 1086: [SCOI2005]王室联邦 (分块+dfs)
Description “余”人国的国王想重新编制他的国家.他想把他的国家划分成若干个省,每个省都由他们王室联邦的一个成员来管理.他的国家有n个城市,编号为1..n.一些城市之间有道路相连,任意两个不 ...
- bzoj 4196 [Noi2015]软件包管理器 (树链剖分+线段树)
4196: [Noi2015]软件包管理器 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 2852 Solved: 1668[Submit][Sta ...