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),以方便使用,這裏我就沒有配置了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章