ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` #!/bin/bash # 要清理的目录及其子目录 BASE_DIR=/root/tmp22/a LOG_FILE="./cleanup.log" # 要保留的天数,即超过这个时间的文件和目录将会被删除 DAYS_TO_KEEP=30 DATE=$(date +"%Y-%m-%d %T") echo "------------------------start--------------------------" >> "$LOG_FILE" echo "" >> "$LOG_FILE" # 删除更新时间超过指定天数的文件 echo "$DATE 删除文件" >> "$LOG_FILE" echo "------------------------------" >> "$LOG_FILE" find "$BASE_DIR" -type f -mtime +$DAYS_TO_KEEP -print | while read file do echo "正在删除文件: $file" >> "$LOG_FILE" rm -f "$file" done echo "" >> "$LOG_FILE" # 删除更新时间超过指定天数且为空的目录 echo "$DATE 删除空目录" >> "$LOG_FILE" echo "------------------------------" >> "$LOG_FILE" find "$BASE_DIR" -type d -mtime +$DAYS_TO_KEEP -empty -print | while read dir do echo "正在删除空目录: $dir" >> "$LOG_FILE" rmdir "$dir" done echo "" >> "$LOG_FILE" echo "$DATE 清理完成" >> "$LOG_FILE" echo "" >> "$LOG_FILE" echo "------------------------end--------------------------" >> "$LOG_FILE" echo "" >> "$LOG_FILE" echo "" >> "$LOG_FILE" ```