trash-cli - FreeDesktop.org 回收站的命令行界面
|下载量|
|捐赠|_
简体中文_
trash-cli 将文件移入回收站,并记录原始路径、删除日期和权限。它使用与 KDE、GNOME 和 XFCE 相同的回收站,但你可以从命令行(和脚本)中调用它。
它提供以下命令::
trash-put 将文件和目录移入回收站。
trash-empty 清空回收站。
trash-list 列出已移入回收站的文件。
trash-restore 恢复已移入回收站的文件。
trash-rm 从回收站中删除单个文件。
用法
将文件移入回收站::
$ trash-put foo
列出已移入回收站的文件::
$ trash-list
2008-06-01 10:30:48 /home/andrea/bar
2008-06-02 21:50:41 /home/andrea/bar
2008-06-23 21:50:49 /home/andrea/foo
在回收站中搜索文件::
$ trash-list | grep foo
2007-08-30 12:36:00 /home/andrea/foo
2007-08-30 12:39:41 /home/andrea/foo
恢复已移入回收站的文件::
$ trash-restore
0 2007-08-30 12:36:00 /home/andrea/foo
1 2007-08-30 12:39:41 /home/andrea/bar
2 2007-08-30 12:39:41 /home/andrea/bar2
3 2007-08-30 12:39:41 /home/andrea/foo2
4 2007-08-30 12:39:41 /home/andrea/foo
要恢复哪个文件 [0..4]: 4
$ ls foo
foo
恢复已移入回收站的文件并覆盖现有文件::
$ echo "original">foo
$ ls
foo
$ trash-put foo
$ echo "new">foo
$ trash-restore --overwrite
0 2022-11-01 22:15:00 /home/andrea/foo
要恢复哪个文件 [0..0]: 0
$ cat foo
original
恢复多个以 ',' 分隔的已删除文件,也支持范围::
$ trash-restore
0 2007-08-30 12:36:00 /home/andrea/foo
1 2007-08-30 12:39:41 /home/andrea/bar
2 2007-08-30 12:39:41 /home/andrea/bar2
3 2007-08-30 12:39:41 /home/andrea/foo2
要恢复哪个文件 [0..3]: 0-2, 3
$ ls foo bar bar2 foo2
foo bar bar2 foo2
从回收站中删除所有文件::
$ trash-empty
仅删除在 之前被删除的文件::
$ trash-empty <days>
示例::
$ date
Tue Feb 19 20:26:52 CET 2008
$ trash-list
2008-02-19 20:11:34 /home/einar/today
2008-02-18 20:11:34 /home/einar/yesterday
2008-02-10 20:11:34 /home/einar/last_week
$ trash-empty 7
$ trash-list
2008-02-19 20:11:34 /home/einar/today
2008-02-18 20:11:34 /home/einar/yesterday
$ trash-empty 1
$ trash-list
2008-02-19 20:11:34 /home/einar/today
仅删除匹配特定模式的文件::
$ trash-rm \*.o
注意:您需要使用引号来保护模式,防止 shell 展开。
FAQ
如何创建顶层 .Trash 目录?
步骤 ::
sudo mkdir --parent /.Trash
sudo chmod a+rw /.Trash
sudo chmod +t /.Trash
我可以将 `rm` 别名为 `trash-put` 吗?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
可以,但不应该。在早期,我认为这样做是个好主意,但现在我改变了想法。
尽管 `trash-put` 的接口似乎与 `rm` 兼容,但它具有不同的语义,这会导致你遇到问题。例如,`rm` 在删除目录时需要 `-R`,而 `trash-put` 则不需要。
但有时我会忘记使用 `trash-put`,真的不行吗?
You could alias rm to something that will remind you to not use it::
alias rm='echo "This is not the command you are looking for."; false'
Then, if you really want to use rm, simply prepend a backslash to bypass the
alias::
\rm file-without-hope
Note that Bash aliases are used only in interactive shells, so using
this alias should not interfere with scripts that expect to use rm.
Where do the trashed files go?
从主分区回收站删除的文件将被移动到这里::
~/.local/share/Trash/
如何自动删除超过 30 天的文件?
运行此命令::
(crontab -l ; echo "@daily $(which trash-empty) 30") | crontab -
这将使用 trash-empty 命令更新你的 crontab 文件,该命令每天运行一次并删除超过 30 天的文件。要查看你的 crontab,请使用:crontab -l
安装
简单方式
要求:
* Python 3(Python 2.7 也可用)
* pipx_(可选,用于在干净环境中安装)
如果 pipx 可用::
pipx install trash-cli
或者,使用原生 pip 安装::
pip install trash-cli
注意:你可能需要将 ~/.local/bin 添加到 PATH::
echo 'export PATH="$PATH":~/.local/bin' >> ~/.bashrc
source ~/.bashrc # 重新加载 .bashrc
要卸载,请使用::
pipx uninstall trash-cli
或者::
pip uninstall trash-cli
前沿版本(从源代码)
First of all you need to uninstall any previous version of trash-cli::
$ [sudo] pip uninstall trash-cli # remove the previous version (with pip)
$ [sudo] apt-get remove trash-cli # remove the previous version (with apt)
$ [sudo] yum uninstall trash-cli # remove the previous version (with yum)
$ ... # refer to the package manager of your distribution
Then install the latest version from git::
$ [sudo] pip install git+https://github.com/andreafrancia/trash-cli
After the user installation you may want to add this line to your .bashrc/.zshrc::
export PATH=~/.local/bin:"$PATH"
From package manager
Debian/Ubuntu (apt)::
sudo apt install trash-cli
Arch Linux (pacman)::
sudo pacman -S trash-cli
Fedora (dnf)::
sudo dnf install trash-cli
MacOS (Homebrew)::
brew install trash-cli
echo 'export PATH="~/homebrew/opt/trash-cli/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Install shell completions
你需要通过以下方式安装::
pipx install 'trash-cli[completion]'
或者::
pip install 'trash-cli[completion]'
然后::
cmds=(trash-empty trash-list trash-restore trash-put trash) for cmd in ${cmds[@]}; do $cmd --print-completion bash | sudo tee /usr/share/bash-completion/completions/$cmd $cmd --print-completion zsh | sudo tee /usr/share/zsh/site-functions/_$cmd $cmd --print-completion tcsh | sudo tee /etc/profile.d/$cmd.completion.csh done
缺少对 Btrfs 卷的支持
trash-cli 不支持 Btrfs 卷。 我没有任何系统,也没有时间和/或知识来实现这种支持。
如果你需要一个回收站实现,可以查看 rmw_ 项目。
.. _rmw: https://github.com/theimpossibleastronaut/rmw
如果你愿意,并且能够,并且知道如何添加对 Btrfs 的支持以及合理的自动化测试,请发送一个拉取请求。
Bug
如果你发现了一个 bug,请在此处报告:
https://github.com/andreafrancia/trash-cli/issues
反馈
你可以通过 andrea@andreafrancia.it 给我发送电子邮件。
开发
环境设置::
python -m venv .venv
source .venv/bin/activate
pip install -r requirements-dev.txt -r requirements.txt
运行测试::
pytest -m 'not slow' # 仅运行快速测试
pytest -m 'slow' # 运行慢速测试
pytest # 运行所有测试
致谢
感谢 Paypal 捐赠者。
感谢 project contributors_。
感谢 JetBrains_ 为开源开发提供的许可
.. |Downloads| image:: https://img.shields.io/pypi/dm/trash-cli .. |Donate| image:: https://www.paypalobjects.com/en_GB/i/btn/btn_donate_SM.gif .. _Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=93L6PYT4WBN5A .. _简体中文: https://github.com/andreafrancia/trash-cli/blob/master/README_zh-CN.rst .. _project contributors: https://github.com/andreafrancia/trash-cli/graphs/contributors .. _JetBrains: https://jb.gg/OpenSource .. _pipx: https://pypa.github.io/pipx/