Skip to content

Instantly share code, notes, and snippets.

@YimianDai
Last active August 22, 2019 01:19
Show Gist options
  • Save YimianDai/2a8e4162f7ebb2afa16627989693f52f to your computer and use it in GitHub Desktop.
Save YimianDai/2a8e4162f7ebb2afa16627989693f52f to your computer and use it in GitHub Desktop.
Linux 的 回收站 trash-cli

Linux 没有回收站,rm 错删文件文件就回不来了,教训实在太惨痛。从 pansz 在知乎上对基于文本的 Linux 为什么没有回收站?的回答中得知,linux 也有类似回收站的工具 trash-cli。这篇日志记录下没有 root 权限下的安装过程。

1. 安装,没有 root 权限

$ git clone https://github.com/andreafrancia/trash-cli.git
$ cd trash-cli
$ python setup.py install --user

事实上,用 pip 更方便,不过我因为看的资料缘故先用了前者

pip install trash-cli --user

2. 系统路径

上面安装好后,只能用 ~/.local/bin/trash-put test.txt 这样的方式使用,我们还要让系统能够知道从 ~/.local/bin 这里找到这些命令。

用 vim 打开 ~/.bash_profile 文件,在最后添加下面代码

export PATH="/work/yimian/.local/bin/:$PATH"

/work/yimian 是我这里的绝对路径,替换成你自己的 trash-put 所在的绝对路径就好

3. 具体使用

具体看这个链接 https://www.ostechnix.com/trash-cli-command-line-trashcan-unix-like-systems/

主要就是 , , , ,

  1. trash-put: 将某些文件放入 trash
  2. trash-list: 查看 trash 中的所有文件
  3. trash-restore: 恢复 trash 中的某个文件
  4. trash-rm: 单独删除 trash 中的文件
  5. trash-empty: 清空 trash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment