在 CentOS 里常说的 “recycle(回收站)” 一般分两种情况,我分别说明 如何自动清理。
CentOS 桌面用户的回收站通常在:
~/.local/share/Trash/files
例如:每隔 7 天清理一次回收站
crontab -e
添加:
0 3 * * 0 rm -rf ~/.local/share/Trash/files/* ~/.local/share/Trash/info/*
说明:
有些管理员会配置:
alias rm='mv -t /data/recycle'
例如:删除 30 天前的文件
crontab -e
0 2 * * * find /data/recycle -type f -mtime +30 -delete
或连同目录:
0 2 * * * find /data/recycle -mtime +30 -exec rm -rf {} \;
Samba 回收站配置示例:
[vfs objects = recycle]
recycle:repository = .recycle
recycle:keeptree = yes
0 1 * * * find /samba/share/.recycle -type f -mtime +14 -delete
如果是 /tmp,CentOS 默认已自动清理:
systemctl status systemd-tmpfiles-clean
✅ 回收站只用于短期防误删
✅ 自动清理周期:7–30 天
✅ 一定要用 find -mtime 而不是 rm -rf *
如果你能告诉我:
我可以直接给你一条可复制的命令。