首页
/ trash-cli 技术文档

trash-cli 技术文档

2024-12-25 15:53:40作者:魏侃纯Zoe

1. 安装指南

安装要求

  • Python 3(Python 2.7 也可以)
  • pipx(可选,用于在干净环境中安装)

安装步骤

使用 pipx 安装(推荐)

如果 pipx 可用,可以使用以下命令安装:

pipx install trash-cli

使用 pip 安装

也可以使用 vanilla pip 安装:

pip install trash-cli

添加到 PATH

安装后,可能需要将 ~/.local/bin 添加到 PATH 中:

echo 'export PATH="$PATH":~/.local/bin' >> ~/.bashrc
source ~/.bashrc # 重新加载 .bashrc

卸载

使用以下命令卸载:

pipx uninstall trash-cli

pip uninstall trash-cli

从源码安装(最新版本)

首先卸载之前的版本:

[sudo] pip uninstall trash-cli # 使用 pip 卸载
[sudo] apt-get remove trash-cli # 使用 apt 卸载
[sudo] yum uninstall trash-cli # 使用 yum 卸载

然后从 git 安装最新版本:

[sudo] pip install git+https://github.com/andreafrancia/trash-cli

安装后,可能需要将 ~/.local/bin 添加到 PATH 中:

export PATH=~/.local/bin:"$PATH"

通过包管理器安装

Debian/Ubuntu (apt)

sudo apt install trash-cli

Arch Linux (pacman)

sudo pacman -S trash-cli

Fedora (dnf)

sudo dnf install trash-cli

安装 shell 补全

使用以下命令安装补全:

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

2. 项目使用说明

基本命令

  • trash-put:将文件或目录移动到回收站。
  • trash-empty:清空回收站。
  • trash-list:列出回收站中的文件。
  • trash-restore:恢复回收站中的文件。
  • trash-rm:从回收站中删除特定文件。

使用示例

将文件移动到回收站

$ trash-put foo

列出回收站中的文件

$ trash-list

恢复回收站中的文件

$ trash-restore

清空回收站

$ trash-empty

删除回收站中超过指定天数的文件

$ trash-empty <days>

删除回收站中匹配特定模式的文件

$ trash-rm \*.o

3. 项目 API 使用文档

命令行接口

trash-cli 提供了以下命令行接口:

  • trash-put:将文件或目录移动到回收站。
  • trash-empty:清空回收站。
  • trash-list:列出回收站中的文件。
  • trash-restore:恢复回收站中的文件。
  • trash-rm:从回收站中删除特定文件。

参数说明

  • trash-put <file>:将指定文件或目录移动到回收站。
  • trash-empty [<days>]:清空回收站,或删除超过指定天数的文件。
  • trash-list:列出回收站中的文件。
  • trash-restore:恢复回收站中的文件。
  • trash-rm <pattern>:删除回收站中匹配指定模式的文件。

4. 项目安装方式

使用 pipx 安装

pipx install trash-cli

使用 pip 安装

pip install trash-cli

从源码安装

[sudo] pip install git+https://github.com/andreafrancia/trash-cli

通过包管理器安装

Debian/Ubuntu (apt)

sudo apt install trash-cli

Arch Linux (pacman)

sudo pacman -S trash-cli

Fedora (dnf)

sudo dnf install trash-cli

通过以上步骤,您可以轻松安装并使用 trash-cli 来管理回收站中的文件。

登录后查看全文
热门项目推荐