在 Debian 里没有 Windows 那种“回收站(Recycle Bin)”机制,不过通常你说的“recycle”可能指下面几种情况之一。我分别说明如何自动清理。
Debian 桌面(如 GNOME)会把删除的文件放在:
~/.local/share/Trash/
rm -rf ~/.local/share/Trash/*
例如:每天清理 7 天前的回收站文件
crontab -e
添加:
0 3 * * * find ~/.local/share/Trash -type f -mtime +7 -delete
⚠️ 注意:
files/ 和 info/ 两个目录0 3 * * * rm -rf ~/.local/share/Trash/files/* ~/.local/share/Trash/info/*
rm 被 alias 到“回收脚本”有些管理员会写:
alias rm='mv -t ~/.trash'
0 4 * * * find ~/.trash -mtime +14 -delete
Debian 默认会自动清理 /tmp
相关服务:
systemctl status tmp.mount
规则由:
/etc/tmpfiles.d/
/usr/lib/tmpfiles.d/tmp.conf
示例(/etc/tmpfiles.d/tmp.conf):
d /tmp 1777 root root 10d
表示:10 天未访问的 /tmp 文件自动删除
后台任务会自动清理回收站(可在管理面板设置保留天数)
在 smb.conf 中:
recycle:keeptree = yes
recycle:repository = .recycle
recycle:maxsize = 0
recycle:exclude = *.tmp
可用 cron 定期清理:
find /srv/samba/.recycle -mtime +30 -delete
✅ 用 systemd timer(现代 Debian 推荐)
例如清理回收站:
~/.config/systemd/user/clean-trash.service
[Service]
ExecStart=/bin/sh -c 'rm -rf ~/.local/share/Trash/files/* ~/.local/share/Trash/info/*'
~/.config/systemd/user/clean-trash.timer
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
启用:
systemctl --user enable --now clean-trash.timer
| 场景 | 自动清理方式 |
|---|---|
| 桌面回收站 | cron / systemd timer |
| 自定义 rm | find + cron |
| /tmp | tmpfiles.d |
| Samba | find + cron |
| Nextcloud | 后台任务 |
如果你能告诉我:
我可以给你完全针对性的自动清理方案。