rm是个强大的命令,特别是rm -rf有时候强大到让你欲哭无泪,当你想清除当前目录下的所有文件和目录时,很简单

$sudo rm -rf ./*

这没什么,但是,但是如果不小心打成这样

$sudo rm -rf /*

兄弟,请节哀!

还 有其他各种各样的杯具,比如打开了很多窗口,有本地机器还有远程的几台服务器,本来想从这台机器执行rm -rf命令,却错误的输

入到了其他机器的终端窗口,总之rm太危险了,特别是带有-rf参数时一定要慎之又慎,但老虎也有打盹的时候啊,所以为什么不给 rm

一剂后悔药呢,嗯,就是它,trash-cli

trash-cli就是带有回收站(Trash)功能的命令行删除工具,其主要特点有

兼容rm命令行接口,可以alias rm为trash-cli

为删除的每一个文件记录原始路径,删除时间和文件访问权限

兼容GNOME和KDE桌面的trash,实现桌面和terminal操作的统一

实现了FreeDesktop.org Trash Specification

支持除home文件系统以外的其他文件系统,比如不同的分区或移动设备分区

安装trash-cli

Ubuntu和Debian仓库里面的版本太低了,而且有严重的bug,去官方网站下载最新版本的trash-cli,然后执行以下命令完成安装

1 $tar xvfz trash-cli-0.12.9.14.tar.gz

2 $cd trash-cli-0.12.9.14

3 $sudo python setup.py install

配置trash-cli替代rm

$vim ~/.bashrc

增添一行

alias rm="trash-put"

以后用rm删除文件的时候,文件会被移动到~/.local/share/Trash/files文件夹下,另一个文件夹~/.local/share/Trash/info下保

存了被删除文件的相关信息

trash-cli命令介绍

trash-put 删除文件

$trash-put foo

foo文件会被放入回收站(trashcan)

trash-list 列出回收站里面的文件

restore-trash 恢复指定的文件

1 $restore-trash

2 ...

3 ...

4 What file to restore [0..n]:

restore-trash会列出回收站里面的所有文件,每个文件前面有一个编号,从0开始,根据提示输入要恢复的文件的编号即可

trash-empty 清空回收站

trash-empty days 删除回收站里面超过指定天数的文件


转载:https://pypi.python.org/pypi/trash-cli/

trash-cli trashes files recording the original path, deletion date, and permissions. It uses the same trashcan used by KDE, GNOME, and XFCE, but you can invoke it from the command line (and scripts).

It provides these commands:

  1. trash-put trashes files and directories.
  2. trash-empty empty the trashcan(s).
  3. trash-list list trashed file.
  4. restore-trash restore a trashed file.

Usage

Trash a file:

  1. $ trash-put foo

List trashed files:

  1. $ trash-list
  2. 2008-06-01 10:30:48 /home/andrea/bar
  3. 2008-06-02 21:50:41 /home/andrea/bar
  4. 2008-06-23 21:50:49 /home/andrea/foo

Search for a file in the trashcan:

  1. $ trash-list | grep foo
  2. 2007-08-30 12:36:00 /home/andrea/foo
  3. 2007-08-30 12:39:41 /home/andrea/foo

Restore a trashed file:

  1. $ restore-trash
  2. 0 2007-08-30 12:36:00 /home/andrea/foo
  3. 1 2007-08-30 12:39:41 /home/andrea/bar
  4. 2 2007-08-30 12:39:41 /home/andrea/bar2
  5. 3 2007-08-30 12:39:41 /home/andrea/foo2
  6. 4 2007-08-30 12:39:41 /home/andrea/foo
  7. What file to restore [0..4]: 4
  8. $ ls foo
  9. foo

Remove all files from the trashcan:

  1. $ trash-empty

Remove only the files that have been deleted before <days> ago:

  1. $ trash-empty <days>

Example:

  1. $ date
  2. Tue Feb 19 20:26:52 CET 2008
  3. $ trash-list
  4. 2008-02-19 20:11:34 /home/einar/today
  5. 2008-02-18 20:11:34 /home/einar/yesterday
  6. 2008-02-10 20:11:34 /home/einar/last_week
  7. $ trash-empty 7
  8. $ trash-list
  9. 2008-02-19 20:11:34 /home/einar/today
  10. 2008-02-18 20:11:34 /home/einar/yesterday
  11. $ trash-empty 1
  12. $ trash-list
  13. 2008-02-19 20:11:34 /home/einar/today

Using it as 'rm' alias

trash-put accept all the options that GNU rm does, if you prefer (I don't) you can set up this alias in your .bashrc:

  1. alias rm='trash-put'

At the present the semantic of trash-put is sligthly different from the one of rm, for example, while rm requires -R for deleting directories trash-put does not. This may change in future.

Keep in mind that Bash aliases are used only in interactive shells, so using this alias should not interfere with scripts that expects to use rm.

Installation (the easy way)

Requirements:

  • Python 2.7
  • setuptools (use apt-get install python-setuptools on Debian)

Installation command:

  1. easy_install trash-cli

Installation from sources

  1. # grab the latest sources
  2. wget https://github.com/andreafrancia/trash-cli/tarball/master
  3.  
  4. # unpack and install
  5. tar xfz andreafrancia-trash-cli-xxxxxxxx.tar.gz
  6. cd andreafrancia-trash-cli-xxxxxxxx
  7. sudo python setup.py install

Bugs and feedback

If you discover a bug please report it to:

https://github.com/andreafrancia/trash-cli/issues

You can reach me via email at me@andreafrancia.it . For twitter use @andreafrancia or #trashcli

Development

Environment setup:

  1. virtualenv env --no-site-packages
  2. source env/bin/activate
  3. pip install -r requirements-dev.txt

Running tests:

  1. nosetests unit_tests # run only unit tests
  2. nosetests integration_tests # run all integration tests
  3. nosetests -A 'not stress_test' # run all tests but stress tests
  4. nosetests # run all tests

Check the installation process before release:

  1. python check_release_installation.py

Profiling unit tests:

  1. pip install gprof2dot
  2. nosetests --with-profile --profile-stats-file stats.pf --profile-restrict=unit_tests unit_tests
  3. gprof2dot -w -f pstats stats.pf | dot -Tsvg >| stats.svg
  4. open stats.svg

为rm命令增加回收站功能的更多相关文章

  1. linux下rm命令修改,增加回收站功能【笔记】

    一个脚本,linux的用户根目录下.bashrc最后加入如下代码,可以修改rm命令,让人们rm时候不再会全部删除,而是会加入到回收站里,以下是根据别人的资料参考修改的,不是原创 加入后,需要sourc ...

  2. Linux将rm命令设置为回收站【转】

    一个方案就是重定向 rm 命令以嫁接为 mv 命令,相当于给 Linux 系统定制了一个回收站. 实现方式如下: ### 重定义rm命令 ### # 定义回收站目录 trash_path='~/.tr ...

  3. 重新嫁接rm命令

    ### 重定义rm命令 #### 定义回收站目录trash_path='~/.trash'# 判断 $trash_path 定义的文件是否存在,如果不存在,那么就创建 $trash_path.if [ ...

  4. 将linux下的rm命令改造成移动文件至回收站【转】

    转自:http://blog.csdn.net/a3470194/article/details/16863803 [-] 将linux下的rm命令改造成移动文件至回收站 将AIX下的rm命令改造成移 ...

  5. ubuntu 修该rm命令使删除文件到回收站

    ubuntu下删除文件到回收站 相信有不少同学和我一样,有因习惯了rm命令,好几次一不小心冲动就删除重要文件的惨痛经历! 目标:将删除成功的文件会放入系统回收站中,位置:~/.local/share/ ...

  6. windows 增加右键功能 -->用命令行打开

    windows 增加右键功能 -->用命令行打开 实现 注册表 以管理员权限CMD 到指定文件夹 Windows Registry Editor Version 5.00 [HKEY_CLASS ...

  7. linux中使用rm命令将文件移到回收站的方法

    今天在终端下,看到我的用户目录下有个-的文件夹(maven生成),相要删除收回点空间,习惯性的用命令 rm -rf ~ ,一回车,猛然想起的时候已经来不及了,世界一下子清静了,想死的心都有了! 没错, ...

  8. 将linux下的rm命令改造成移动文件至回收站

    将linux下的rm命令改造成移动文件至回收站 rm是Linux下文件删除的命令,它是Linux下非常强大却又非常危险的一条命令,特别是rm -rf有时候强大到让你欲哭无泪,当你想清除当前目录下的所有 ...

  9. 【Linux下禁用rm命令之建立回收站】

    第一步 创建回收站目录 # 根据自己的习惯,找个位置创建一个用作回收文件的目录 # 我们这里将在root目录下面创建一个名为".trash"的隐藏文件 [root@fedora ~ ...

随机推荐

  1. cocos2d-js屏幕任何位置点击开始的实现

    ctor:function () { this._super(); if ('mouse' in cc.sys.capabilities) cc.eventManager.addListener({ ...

  2. hdu5072-Coprime(容斥原理)

    题意:给N个互不相同的数,选择出两两互质或者两两不互质的三个数,有多少种选法. 题解:一共有C(N,3)中选择方式,减去不符合要求的,剩下的就是答案. 详见 http://blog.csdn.net/ ...

  3. MYSQL数据库性能调优之七:其他(读写分离、分表等)

    一.分表 水平划分 垂直划分 二.读写分离 三.选择合理的数据类型 特别是主键 四.文件.图片等大文件使用文件系统存储 五.数据库参数配置 注意:max_connections最大连接数一般设置在10 ...

  4. spring properties resolve 问题

    在stackoverflow上看到一个问题 配置如下: <context:property-placeholder location="/WEB-INF/application-cus ...

  5. *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL

    kei编译时提示: *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL *** WARNING L1:reference made to unresolved ext ...

  6. CSS画出的各种形状图

    利用CSS可以画出各种需要的图形目录[1]矩形[2]圆形[3]椭圆[4]直角三角形[5]正三角形[6]平行四边形[7]梯形[8]六角星[9]六边形[10]五角星简单图形 矩形div{ width: 1 ...

  7. 程序设计第三次作业--C++计算器初始部分

    面向对象程序设计作业3--C++计算器初始部分 Github 链接:https://github.com/luojingzhao/object-oriented/tree/master/calcula ...

  8. ThinkPHP C+F方式

    ThinkPHP常用C+F方法进行配置设置于缓存设置 比如常见的 C(F('smtp'),'smtp');表示获取F方法中smtp缓存,设置配置为smtp函数 C方法是ThinkPHP用于设置.获取, ...

  9. Linux内核完全注释之编程语言和环境(一)

    as86汇编器 1.来源与对于linux的用途 as86来源minix-386开发的intel 8086.80386汇编编译程序和链接程序,他主要为linux创建16位的启动引导扇区程序boot/bo ...

  10. 25.怎样创建一个Swift项目?

    经历前面三部分的学习之后,我们对于Swift的有了基本的了解,知道它的基础语法,也知道了类.结构体.枚举.协议.扩展等等内容.但知道上面这些内容,并不代表我们就能很好的进行实际的项目开发了,本部分内容 ...