#!/bin/bash

# Set the base directory (default is current directory)
BASE_DIR="${1:-.}"

# Find all directories under the base directory
find "$BASE_DIR" -mindepth 1 -maxdepth 1 -type d | while read -r dir; do
    # Get the total size of the directory in bytes
    size_bytes=$(du -sb "$dir" 2>/dev/null | cut -f1)

    # Check if size is less than 1MB (1 * 1024 * 1024 = 1048576 bytes)
    if [ "$size_bytes" -lt 5048576 ]; then
        echo "Deleting directory <$dir> (size: $size_bytes bytes)"
        rm -rf "$dir"
    fi
done
