Ubuntu 回收站功能全览
一 核心概念与位置
[Trash Info]
Path=/home/user/Documents/test.txt
DeletionDate=2024-01-15T10:30:00
二 图形界面操作与自动清理
三 命令行工具与常用命令
sudo apt install trash-clitrash-put <文件> 或 trash <文件>:移入回收站trash-list:列出回收站内容trash-restore:交互式选择并恢复trash-rm <条目>:从回收站永久删除指定条目trash-empty:清空回收站sudo apt install gvfs-bingvfs-trash <文件>:移入回收站gvfs-trash-restore:交互式恢复gvfs-trash-empty:清空回收站四 进阶配置与自动化
alias rm='trash-put',保存后执行 source ~/.bashrc\rm)或在关键场景显式使用绝对路径 /bin/rm。# 创建服务
sudo tee /etc/systemd/system/trash-cleanup.service >/dev/null <<'EOF'
[Unit]
Description=清理回收站
[Service]
Type=oneshot
ExecStart=/usr/bin/trash-empty --age 7d
EOF
# 创建定时器
sudo tee /etc/systemd/system/trash-cleanup.timer >/dev/null <<'EOF'
[Unit]
Description=每天检查并清理回收站
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
EOF
# 启用
sudo systemctl daemon-reload
sudo systemctl enable --now trash-cleanup.timer
trash-empty --age 7d 会删除回收站中超过 7 天 的条目;该方式对命令行与图形删除均有效(统一作用于同一用户的回收站目录)。