Skip to main content

Posts

Showing posts from October, 2026

Safe interactive log cleanup script

 You can use a safe interactive log cleanup script that: Scans /var/log for the largest files. Shows their sizes. Asks for confirmation before clearing each file. Clears only files you approve. Keeps the log files in place, so services can continue writing to them. Script: cleanup_logs.sh ################################################### #!/bin/bash LOG_DIR="/var/log" MIN_SIZE="+100M" if [[ $EUID -ne 0 ]]; then     echo "Please run this script as root."     exit 1 fi echo "========== Disk Usage Before ==========" df -h "$LOG_DIR" du -sh "$LOG_DIR" echo echo "Scanning log files larger than 100 MB..." echo find "$LOG_DIR" -type f -size "$MIN_SIZE" -print0 | while IFS= read -r -d '' file; do     # Skip symlinks     [[ -L "$file" ]] && continue     size=$(du -h "$file" | cut -f1)     echo "--------------------------------------"     echo "File : $f...