在 CentOS 里“recycle(回收站)”通常出现在两种场景:
下面分别说明定时清理方法。
CentOS 桌面回收站路径一般是:
~/.local/share/Trash/files
例如:每天凌晨 3 点清理 7 天前的文件
crontab -e
添加:
0 3 * * * find /home/*/.local/share/Trash/files -type f -mtime +7 -delete
⚠️ 如果有多个用户,建议逐个用户处理,或用通配符(如上)
如果你是自己做了类似:
mv file /data/recycle/
crontab -e
0 2 * * * find /data/recycle -type f -mtime +30 -delete
或连目录一起删:
0 2 * * * find /data/recycle -mtime +30 -exec rm -rf {} \;
vim /usr/local/bin/clean_recycle.sh
#!/bin/bash
find /data/recycle -type f -mtime +30 -delete
chmod +x /usr/local/bin/clean_recycle.sh
vim /etc/systemd/system/clean-recycle.service
[Unit]
Description=Clean recycle dir
[Service]
Type=oneshot
ExecStart=/usr/local/bin/clean_recycle.sh
vim /etc/systemd/system/clean-recycle.timer
[Unit]
Description=Daily clean recycle
[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true
[Install]
WantedBy=timers.target
systemctl daemon-reload
systemctl enable --now clean-recycle.timer
| 参数 | 含义 |
|---|---|
-mtime +7 |
7 天前 |
-mmin +60 |
60 分钟前 |
-type f |
只删文件 |
-delete |
直接删除 |
✅ 先测试:
find /data/recycle -mtime +30
✅ 避免误删:
find /data/recycle -mtime +30 -print
✅ 重要数据不要放 recycle 长期保留
如果你能告诉我:
我可以直接帮你写一份可用配置。