温馨提示×

CentOS回收站怎么设置自动清理

小樊
62
2025-09-07 22:25:41
栏目: 智能运维

在CentOS中设置回收站自动清理,可参考以下方法:

  • 使用trash-cli工具(推荐)
    1. 安装trash-clisudo yum install trash-cli
    2. 编辑配置文件/etc/trash-cli.conf,添加或修改auto_empty = 60(单位:分钟,可根据需求调整)。
    3. 重启trash-cli服务(若支持):sudo systemctl restart trash-cli
    4. 若上述方法无效,可手动设置定时任务,编辑crontabcrontab -e,添加如0 0 * * * /usr/bin/trash-empty(每天凌晨清空)。
  • 自定义脚本+定时任务
    1. 创建回收站目录(若未创建):mkdir -p ~/.local/share/Trash/files
    2. 编写清空脚本,如#!/bin/bash find ~/.local/share/Trash/files -type f -mtime +30 -exec rm -f {} \;(删除30天前文件),保存为clean_trash.sh并赋予执行权限chmod +x clean_trash.sh
    3. 配置定时任务:crontab -e,添加0 0 * * * /path/to/clean_trash.sh(每天凌晨执行)。

0