Ubuntu Recycle(回收站/Trash)清理策略主要围绕自动清理、手动清理及辅助工具展开,以下是具体方案:
trash-cli与Cron定时任务trash-cli是命令行工具,需配合Cron实现定时自动清理。
sudo apt update && sudo apt install trash-cli。clean_recycle_bin.sh),设置清理条件(如文件数量或回收站大小),示例代码:#!/bin/bash
MAX_FILES=100 # 最大文件数阈值
FILE_COUNT=$(ls -1 ~/.local/share/Trash/files/* | wc -l)
if [ "$FILE_COUNT" -gt "$MAX_FILES" ]; then
trash-empty # 清空回收站
fi
chmod +x clean_recycle_bin.sh。crontab -e,添加定时规则(如每天凌晨1点执行):0 1 * * * /path/to/clean_recycle_bin.sh。autotrash工具autotrash是专门用于自动清理回收站的工具,支持按时间或磁盘空间触发清理。
sudo apt install autotrash。autotrash -d 30;autotrash --max-free 100M -d 30。若不想安装软件,可通过系统自带命令实现简单自动清理。
#!/bin/bash
MAX_SIZE=100 # 最大容量(MB)
TOTAL_SIZE=$(du -sm ~/.local/share/Trash/files | awk '{print $1}')
if [ "$TOTAL_SIZE" -gt "$MAX_SIZE" ]; then
trash-empty
fi
trash-cli方法,将脚本路径添加到Cron中。rm -rf ~/.local/share/Trash/*(谨慎使用,此操作不可逆);ls ~/.local/share/Trash/files/(确认文件后再执行清理)。sudo apt install bleachbit;journalctl --vacuum-time=30d(保留最近30天的日志);sudo apt clean(删除已下载的软件包缓存);sudo apt autoremove --purge(删除不再需要的旧内核及配置文件)。