linux防误删工具trash-cli

    技术2023-08-19  85

    平时删去文件都是使用的rm-rf

    这个存在一个致命的问题,删去了就没法恢复了,虽然时刻保持谨慎,但也不能保证不会误删

    因此,trash-cli诞生了

    trash-cli理解成平时我们在window 里面使用的回收站就行,安装使用都很简单。

    1)首先我们需要去下载安装包

     [root@VM_0_9_centos trash-cli]# git clone https://github.com/andreafrancia/trash-cli

    2)设置环境变量

    在/etc/profile最后一行添加环境变量

    vim /etc/profile export PATH=/opt/test/trash-cli:$PATH source /etc/profile

     3)执行sh安装脚本

        cd trash-cli     sh install-rpm.sh

    这时候就会出现很多可执行命令 

     试一下:

    [root@VM_0_9_centos trash-cli]# trash -h Usage: trash [OPTION]... FILE... Put files in trash Options: --version show program's version number and exit -h, --help show this help message and exit -d, --directory ignored (for GNU rm compatibility) -f, --force ignored (for GNU rm compatibility) -i, --interactive ignored (for GNU rm compatibility) -r, -R, --recursive ignored (for GNU rm compatibility) --trash-dir=TRASHDIR use TRASHDIR as trash folder -v, --verbose explain what is being done To remove a file whose name starts with a '-', for example '-foo', use one of these commands: trash -- -foo trash ./-foo Report bugs to https://github.com/andreafrancia/trash-cli/issues

    解释一下对应命令  trash-list----------------------列出回收站的数据 trash-put----------------------删除linux数据到回收站 trash-restore----------------恢复回收站数据到linux trash-rm----------------------删除回收站中指定文件

    牛刀小试一下

    [root@VM_0_9_centos test]# ll total 4460 -rw-r--r-- 1 root root 1971504 Mar 7 17:09 a.csv -rw-r--r-- 1 root root 2577408 Mar 7 17:16 a.xls -rw-r--r-- 1 root root 102 Mar 7 17:16 bb.py -rw-r--r-- 1 root root 77 Mar 7 18:36 scihub.py drwxr-xr-x 11 root root 4096 Jul 3 15:16 trash-cli [root@VM_0_9_centos test]# trash-put a.csv [root@VM_0_9_centos test]# ll total 2532 -rw-r--r-- 1 root root 2577408 Mar 7 17:16 a.xls -rw-r--r-- 1 root root 102 Mar 7 17:16 bb.py -rw-r--r-- 1 root root 77 Mar 7 18:36 scihub.py drwxr-xr-x 11 root root 4096 Jul 3 15:16 trash-cli [root@VM_0_9_centos test]# trash-list 2020-07-03 15:29:53 /opt/test/a.csv [root@VM_0_9_centos test]# trash-restore 0 2020-07-03 15:29:53 /opt/test/a.csv What file to restore [0..0]: Exiting [root@VM_0_9_centos test]# ll total 2532 -rw-r--r-- 1 root root 2577408 Mar 7 17:16 a.xls -rw-r--r-- 1 root root 102 Mar 7 17:16 bb.py -rw-r--r-- 1 root root 77 Mar 7 18:36 scihub.py drwxr-xr-x 11 root root 4096 Jul 3 15:16 trash-cli

    我们可以看到现在已经删去了文件a.csv

    接下来,我们尝试着恢复一下:

    [root@VM_0_9_centos test]# trash-restore 0 2020-07-03 15:29:53 /opt/test/a.csv What file to restore [0..0]: 0 [root@VM_0_9_centos test]# ll total 4460 -rw-r--r-- 1 root root 1971504 Mar 7 17:09 a.csv -rw-r--r-- 1 root root 2577408 Mar 7 17:16 a.xls -rw-r--r-- 1 root root 102 Mar 7 17:16 bb.py -rw-r--r-- 1 root root 77 Mar 7 18:36 scihub.py drwxr-xr-x 11 root root 4096 Jul 3 15:16 trash-cli

    恢复步骤是:输入命令trash-restore并回车,然后再 输入 回收站里面该文件的序号(回收站里面最坐标对应的数字就是序号),因为回收站文件只有一个,因此输入的0然后回车。

     最后,也可以配别名(alias),以方便使用,这里我就没有配置了

    Processed: 0.015, SQL: 9