你提到的 “centos recycle”,通常是指 CentOS 中文件删除后进入的回收站目录(常见是 .Trash 或某些服务如 Samba、Nextcloud、自建回收站脚本产生的 recycle 目录)。
下面按常见场景给你几种定时删除方法。
Samba 自带 recycle 模块,可直接在配置里设置自动清理。
vi /etc/samba/smb.conf
[share]
path = /data/share
read only = no
recycle:repository = .recycle
recycle:keeptree = yes
recycle:versions = yes
recycle:maxsize = 0
recycle:exclude = *.tmp *.log
recycle:touch = yes
crontab -e
每天凌晨清理 7 天前的文件:
0 0 * * * find /data/share/.recycle -type f -mtime +7 -delete
比如:
/root/recycle
/home/user/recycle
crontab -e
0 2 * * * find /path/to/recycle -type f -mtime +30 -delete
0 2 * * * find /path/to/recycle -type d -empty -delete
比 cron 更现代。
vi /etc/systemd/system/clean-recycle.service
[Unit]
Description=Clean recycle bin
[Service]
Type=oneshot
ExecStart=/usr/bin/find /path/to/recycle -type f -mtime +7 -delete
vi /etc/systemd/system/clean-recycle.timer
[Unit]
Description=Daily clean recycle
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
systemctl enable clean-recycle.timer
systemctl start clean-recycle.timer
-print 测试,再 -deletefind /path/to/recycle -mtime +7 -print
/ 或 Home>> /var/log/recycle-clean.log 2>&1
如果你能告诉我:
我可以给你精确命令。