linux-server-cleaner-script/remove-big-folders-unused-docker.sh

53 lines
1.3 KiB
Bash

#!/bin/bash
echo "Displaying the 20 largest files on the system:"
find / -xdev -type f -exec du -h {} + 2>/dev/null | sort -rh | head -n 20
echo -e "\nThe following files are safe to remove and will free up space:"
SAFE_TO_REMOVE=(
"/var/log/btmp"
"/usr/local/nginx/logs/access.log"
"/usr/local/nginx/logs/error.log"
"/var/log/nginx/access.log"
"/var/log/letsencrypt/letsencrypt.log"
"/var/log/nginx/yarr_access.log"
"/var/lib/apt/lists/*"
)
for file in "${SAFE_TO_REMOVE[@]}"; do
if [ -e "$file" ] || [ -d "$file" ]; then
echo "$file"
fi
done
read -p "Do you want to proceed with the removal? (y/N): " CONFIRM
if [[ "$CONFIRM" =~ ^[Yy]$ ]]; then
echo -e "\nRemoving files..."
for file in "${SAFE_TO_REMOVE[@]}"; do
if [ -f "$file" ]; then
> "$file"
echo "Truncated: $file"
elif [ -d "$file" ]; then
rm -rf "$file"
echo "Removed directory: $file"
fi
done
echo -e "\nCleaning APT cache..."
apt clean
echo -e "\nPruning Docker (if installed)..."
if command -v docker >/dev/null 2>&1; then
docker system prune -af
docker volume prune -f
fi
echo -e "\nCleaning journal logs..."
journalctl --vacuum-size=50M
echo -e "\nCleanup completed."
else
echo "Operation cancelled."
fi