温馨提示×

centos recycle怎样设置时限

小樊
36
2026-09-06 06:49:37
栏目: 智能运维

在 CentOS 中,通常没有 Windows 那样的“回收站(Recycle Bin)”机制,所以你提到的“recycle 时限”一般出现在以下两种场景中:


一、如果是 Samba 的 recycle(回收站)

如果你是搭建了 Samba 文件共享,并启用了 recycle 模块,可以通过参数设置“保留时间”。

示例配置(/etc/samba/smb.conf

[shared]
path = /data/shared
read only = no
recycle:repository = .recycle
recycle:keeptree = yes
recycle:versions = yes
recycle:maxsize = 0
recycle:touch = yes
recycle:directory_mode = 0777
recycle:subdir_mode = 0700

设置“时限”(自动清理)

Samba 本身 没有直接的过期时间参数,但可以用 cron + find 实现:

# 每天删除 7 天前的回收站文件
find /data/shared/.recycle -type f -mtime +7 -delete

加入 cron:

crontab -e
0 2 * * * find /data/shared/.recycle -type f -mtime +7 -delete

二、如果是 rm 误删防护(如 trash-cli / safe-rm)

CentOS 可用 trash-cli 模拟回收站。

安装

yum install epel-release -y
yum install trash-cli -y

使用

trash-put file.txt

清理时限(使用 cron)

# 清空 30 天前的回收站
0 3 * * * trash-empty 30

三、如果是 系统日志 / 临时文件(/tmp)

CentOS 使用 systemd-tmpfiles

vim /etc/tmpfiles.d/tmp.conf

示例(10 天清理):

d /tmp 1777 root root 10d

应用:

systemd-tmpfiles --clean

总结

场景 是否支持时限 实现方式
Samba recycle ❌ 无原生参数 cron + find
trash-cli trash-empty N
/tmp 临时文件 systemd-tmpfiles

如果你能说明 “recycle” 是用在什么环境(Samba / 脚本 / 桌面 / 服务器),我可以给你更精确的配置。

0