温馨提示×

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

小樊
61
2025-09-01 22:03:43
栏目: 智能运维

CentOS回收站自动清理可通过配置定时任务实现,以下是具体方法:

  • 方法一:使用trash-cli工具(推荐)
    1. 安装trash-cli:sudo yum install trash-cli
    2. 编辑配置文件/etc/trash-cli.conf,添加auto_empty = 60(单位:分钟,可根据需求调整)。
    3. 重启trash-cli服务:sudo systemctl restart trash-cli
    4. 若上述方法无效,可手动设置定时任务,编辑crontab:crontab -e,添加0 2 * * * /usr/bin/trash-empty(每天凌晨2点清空)。
  • 方法二:自定义脚本+定时任务
    1. 创建回收站目录(如~/.trash)。
    2. 编写清理脚本,例如删除超过30天的文件:
#!/bin/bash
TRASH_DIR="$HOME/.trash"
find "$TRASH_DIR" -type f -mtime +30 -exec rm -f {} \;
3. 赋予脚本执行权限:`chmod +x ~/clean_trash.sh`。
4. 添加定时任务:`crontab -e`,添加`0 0 * * * ~/clean_trash.sh`(每天凌晨执行)。

0