linux防误删工具trash-cli

平时删去文件都是使用的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),以方便使用,这里我就没有配置了

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值