Add step_tmp_cache: find >7d dry-run + confirmed rm

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-22 00:18:45 +07:00
co-authored by Claude
parent f50579efb2
commit a49f26adc8
+29
View File
@@ -294,6 +294,34 @@ step_snap() {
echo "" echo ""
} }
# -----------------------------
# Bước 6: /tmp & cache cũ — liệt kê file >7 ngày, xác nhận rồi xóa
# -----------------------------
step_tmp_cache() {
echo "${C_TITLE}--- [/tmp & Cache cũ] ---${C_RESET}"
local days=7
echo " Tìm file cũ hơn ${days} ngày trong /tmp /var/tmp:"
local old_files
old_files=$(sudo find /tmp /var/tmp -type f -mtime +"$days" 2>/dev/null)
if [ -z "$old_files" ]; then
echo "${C_OK} ✓ Không có file cũ >${days} ngày.${C_RESET}"
echo ""
return
fi
local count total_kb total_mib
count=$(printf '%s\n' "$old_files" | grep -c .)
total_kb=$(printf '%s\n' "$old_files" | xargs sudo du -ck 2>/dev/null | tail -1 | cut -f1)
total_mib=$(( total_kb / 1024 ))
echo "${C_DEL} ✗ ${count} file, ~${total_mib} MiB.${C_RESET}"
printf '%s\n' "$old_files" | head -20 | sed 's/^/ - /'
[ "$count" -gt 20 ] && echo " ... (và $((count - 20)) file nữa)"
if confirm_yn "Xóa các file cũ >${days} ngày?"; then
printf '%s\n' "$old_files" | xargs sudo rm -f --
echo "${C_OK} ✓ Đã xóa.${C_RESET}"
fi
echo ""
}
# ----------------------------- # -----------------------------
# Chạy tuần tự 6 bước (stub — các bước thêm ở Task 4-9) # Chạy tuần tự 6 bước (stub — các bước thêm ở Task 4-9)
# ----------------------------- # -----------------------------
@@ -303,6 +331,7 @@ run_all_steps() {
step_journal step_journal
step_pkg_cache step_pkg_cache
step_snap step_snap
step_tmp_cache
} }
# ----------------------------- # -----------------------------