在 Debian 里并不存在 Windows 风格的“回收站(Recycle Bin)”机制,因此“自动化 Debian recycle”通常有以下几类含义和实现方式。下面我按常见需求给你说明。
trash-cli(最推荐)trash-cli 提供类桌面环境的回收站功能,可在命令行使用。
sudo apt update
sudo apt install trash-cli
trash-put file.txt # 删除到回收站
trash-list # 查看回收站
trash-restore # 恢复
trash-empty # 清空
trash-empty 30 # 清空 30 天前的
alias 防止误删:alias rm='trash-put'
写入 ~/.bashrc
crontab -e
添加:
0 3 * * * /usr/bin/trash-empty 7
或使用 systemd timer(服务器更推荐)
inotify + 脚本适合“自动 recycle 某些目录的文件”
sudo apt install inotify-tools
示例脚本:
#!/bin/bash
DIR="/data/watch"
inotifywait -m -e delete "$DIR" | while read path action file; do
trash-put "$path$file"
done
⚠️ 注意:inotify 是“事件后触发”,不能真正拦截 rm
示例(Btrfs):
btrfs subvolume snapshot /data /data/snap-$(date +%F)
| 需求 | 推荐方案 |
|---|---|
| 命令行防误删 | trash-cli + alias rm |
| 自动清理 | cron / systemd |
| 服务器安全 | 快照(Btrfs/ZFS) |
| 监控目录 | inotify + trash |
如果你能补充说明:
我可以直接帮你写一套可落地的自动化配置。