在 Debian 系统中,“回收站(recycle)”通常取决于你使用的是哪种环境或工具:
trash-cli、自建 /tmp、或某些服务的回收目录下面按常见场景说明 如何定时清理回收站/回收目录。
sudo apt update
sudo apt install trash-cli
trash-empty # 清空所有
trash-empty 30 # 删除 30 天前的
编辑当前用户的 cron:
crontab -e
例如每天凌晨 3 点清理 7 天前的回收站:
0 3 * * * /usr/bin/trash-empty 7
桌面回收站通常位于:
~/.local/share/Trash/
0 4 * * * find ~/.local/share/Trash -type f -mtime +7 -delete
或更安全一点:
0 4 * * * rm -rf ~/.local/share/Trash/*
⚠️ 注意:root 用户和不同用户的 Trash 是分开的。
Debian 默认会通过 systemd-tmpfiles 清理 /tmp。
查看规则:
cat /usr/lib/tmpfiles.d/tmp.conf
一般默认:
d /tmp 1777 root root 10d
表示 10 天清理一次。
systemd-tmpfiles --clean
如果你说的是 Samba 的 recycle 模块:
[share]
path = /srv/samba/share
recycle:repository = .recycle
recycle:keeptree = yes
recycle:maxsize = 0
0 2 * * * find /srv/samba/share/.recycle -type f -mtime +30 -delete
创建服务:
sudo nano /etc/systemd/system/trash-clean.service
[Unit]
Description=Clean trash older than 7 days
[Service]
Type=oneshot
ExecStart=/usr/bin/trash-empty 7
创建 timer:
sudo nano /etc/systemd/system/trash-clean.timer
[Unit]
Description=Daily trash cleanup
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
启用:
sudo systemctl enable --now trash-clean.timer
| 场景 | 推荐方式 |
|---|---|
| 命令行回收站 | trash-cli + cron |
| 桌面回收站 | cron 清理 ~/.local/share/Trash |
| 系统临时文件 | systemd-tmpfiles |
| Samba 回收站 | find + cron |
| 服务器 | systemd timer |
如果你能说明 具体是哪种“recycle”(桌面 / Samba / 自建目录 / 容器),我可以给你更精确的配置。