zoukankan      html  css  js  c++  java
  • 使用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安装包

    1. [root@VM_54_118_centos others]# git clone https://github.com/andreafrancia/trash-cli.git
    2. Cloning into 'trash-cli'...
    3. remote: Enumerating objects: 4556, done.
    4. remote: Total 4556 (delta 0), reused 0 (delta 0), pack-reused 4556
    5. Receiving objects: 100% (4556/4556), 1.17 MiB | 716.00 KiB/s, done.
    6. Resolving deltas: 100% (2791/2791), done.
    7.  
    8. 进入下载目录
    9. [root@VM_54_118_centos others]# cd trash-cli/
    10. [root@VM_54_118_centos trash-cli]# ll
    11. total 112
    12. -rw-r--r-- 1 root root 251 Feb 2 17:29 bugs.txt
    13. -rw-r--r-- 1 root root 4766 Feb 2 17:29 check_release_installation.py
    14. -rw-r--r-- 1 root root 17992 Feb 2 17:29 COPYING
    15. -rw-r--r-- 1 root root 1432 Feb 2 17:29 CREDITS.txt
    16. drwxr-xr-x 3 root root 4096 Feb 2 17:29 docs
    17. -rw-r--r-- 1 root root 782 Feb 2 17:29 DONE.txt
    18. -rw-r--r-- 1 root root 3408 Feb 2 17:29 HISTORY.txt
    19. -rwxr-xr-x 1 root root 240 Feb 2 17:29 install-rpm.sh
    20. drwxr-xr-x 2 root root 4096 Feb 2 17:29 integration_tests
    21. drwxr-xr-x 3 root root 4096 Feb 2 17:29 man
    22. -rw-r--r-- 1 root root 78 Feb 2 17:29 MANIFEST.in
    23. -rw-r--r-- 1 root root 4774 Feb 2 17:29 README.rst
    24. -rw-r--r-- 1 root root 24 Feb 2 17:29 requirements-dev.txt
    25. -rwxr-xr-x 1 root root 293 Feb 2 17:29 setup.cfg
    26. -rw-r--r-- 1 root root 2423 Feb 2 17:29 setup.py
    27. drwxr-xr-x 2 root root 4096 Feb 2 17:29 tasks
    28. -rw-r--r-- 1 root root 799 Feb 2 17:29 TODO.txt
    29. drwxr-xr-x 2 root root 4096 Feb 2 17:29 trashcli
    30. -rwxr-xr-x 1 root root 127 Feb 2 17:29 trash-put
    31. -rwxr-xr-x 1 root root 126 Feb 2 17:29 trash-rm
    32. drwxr-xr-x 2 root root 4096 Feb 2 17:29 unit_tests
    33. -rw-r--r-- 1 root root 243 Feb 2 17:29 Vagrantfile

    2、开始安装

    1. [root@VM_54_118_centos trash-cli]# python setup.py install
    2. .......
    3. running install_scripts
    4. copying build/scripts-2.7/trash-rm -> /usr/bin
    5. copying build/scripts-2.7/trash-list -> /usr/bin
    6. copying build/scripts-2.7/trash-put -> /usr/bin
    7. copying build/scripts-2.7/trash-empty -> /usr/bin
    8. copying build/scripts-2.7/trash -> /usr/bin
    9. copying build/scripts-2.7/trash-restore -> /usr/bin
    10. changing mode of /usr/bin/trash-rm to 755
    11. changing mode of /usr/bin/trash-list to 755
    12. changing mode of /usr/bin/trash-put to 755
    13. changing mode of /usr/bin/trash-empty to 755
    14. changing mode of /usr/bin/trash to 755
    15. changing mode of /usr/bin/trash-restore to 755
    16. running install_data
    17. copying man/man1/trash-empty.1 -> /usr/share/man/man1
    18. copying man/man1/trash-list.1 -> /usr/share/man/man1
    19. copying man/man1/trash-restore.1 -> /usr/share/man/man1
    20. copying man/man1/trash-put.1 -> /usr/share/man/man1
    21. copying man/man1/trash-rm.1 -> /usr/share/man/man1
    22. running install_egg_info
    23. Writing /usr/lib/python2.7/site-packages/trash_cli-0.17.1.14-py2.7.egg-info

    3、安装成功后我们的系统就有了以下工具.

    1. [root@VM_54_118_centos ~]# ll /usr/bin/ | grep trash
    2. -rwxr-xr-x 1 root root 123 Feb 2 17:43 trash
    3. -rwxr-xr-x 1 root root 125 Feb 2 17:43 trash-empty
    4. -rwxr-xr-x 1 root root 124 Feb 2 17:43 trash-list
    5. -rwxr-xr-x 1 root root 123 Feb 2 17:43 trash-put
    6. -rwxr-xr-x 1 root root 127 Feb 2 17:43 trash-restore
    7. -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命令

    1. [root@VM_54_118_centos ~]# vim .bashrc
    2. # .bashrc
    3. #alias rm='rm -i'
    4. alias rm='trash-put'

    5、实验测试

    删除测试:

    1. [root@VM_54_118_centos ~]# rm -rf dump.rdb
    2. [root@VM_54_118_centos ~]# ll ~/.local/share/Trash/files
    3. -rw-r--r-- 1 root root 123 Jul 17 2018 dump.rdb
    4.  
    5. [root@VM_54_118_centos ~]# trash-list
    6. 2019-02-02 18:02:33 /root/dump.rdb

    还原删除的文件

    1. [root@VM_54_118_centos ~]# trash-restore /root/dump.rdb
    2. 0 2019-02-02 18:01:08 /root/dump.rdb.bak
    3. 1 2019-02-02 18:02:33 /root/dump.rdb
    4. What file to restore [0..1]: 1
    5.  
    6. 还原成功
    7. [root@VM_54_118_centos ~]# ll /root/dump.rdb
    8. -rw-r--r-- 1 root root 123 Jul 17 2018 /root/dump.rdb

    备注:

    trash-put命令会把我们想要删除的文件移动到~/.local/share/Trash/files 中。
    相关信息记录在~/.local/share/Trash/info中。

  • 相关阅读:
    JAVA内部类的使用
    JAVA try&&catch
    是时候清除你的僵尸代码了
    修复EXE文件无法打开
    MFC实现播放SWF
    JAVA实现swap
    Java RandomAccessFile用法
    程序员如何做出“不难看”的设计
    JAVA期末考试试题
    java static类
  • 原文地址:https://www.cnblogs.com/cheyunhua/p/10435163.html
Copyright © 2011-2022 走看看