Skip to content

Instantly share code, notes, and snippets.

@thanhdevapp
Last active June 14, 2025 06:24
Show Gist options
  • Save thanhdevapp/f9d2adefafba23c21ba3ca96d58be10a to your computer and use it in GitHub Desktop.
Save thanhdevapp/f9d2adefafba23c21ba3ca96d58be10a to your computer and use it in GitHub Desktop.
cleanup-angular.sh on mac os
#!/bin/bash
# Prompt for input base directory
read -rp "๐Ÿ“‚ Enter the base directory to search under (e.g., ./ or /Users/you/project): " base_dir
# Validate input
if [ ! -d "$base_dir" ]; then
echo "โŒ Directory '$base_dir' does not exist. Exiting."
exit 1
fi
echo "๐Ÿ” Searching for .angular folders inside subdirectories of '$base_dir'..."
# Initialize array
angular_dirs=()
# Use while loop instead of mapfile for macOS compatibility
while IFS= read -r dir; do
angular_dirs+=("$dir")
done < <(find "$base_dir" -mindepth 2 -type d -name ".angular")
# If no results found
if [ ${#angular_dirs[@]} -eq 0 ]; then
echo "โœ… No .angular folders found."
exit 0
fi
# Display found folders with size
echo "๐Ÿ“ฆ Found the following .angular folders:"
for dir in "${angular_dirs[@]}"; do
du -sh "$dir"
done
# Calculate total size
total_kb=$(du -s "${angular_dirs[@]}" | awk '{sum += $1} END {print sum}')
total_gb=$(awk -v kb="$total_kb" 'BEGIN {printf "%.2f", kb/1024/1024}')
echo "๐Ÿงฎ Total disk usage: $total_gb GB"
# Confirm deletion
read -p "โ—Are you sure you want to delete all these .angular folders? (y/n): " confirm
if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then
for dir in "${angular_dirs[@]}"; do
echo "๐Ÿ—‘๏ธ Deleting $dir..."
rm -rf "$dir"
done
echo "โœ… All .angular folders have been deleted."
else
echo "โŒ Operation cancelled. No folders were deleted."
fi
@thanhdevapp
Copy link
Author

chmod +x cleanup-angular.sh
./cleanup-angular.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment