Last active
June 14, 2025 06:24
-
-
Save thanhdevapp/f9d2adefafba23c21ba3ca96d58be10a to your computer and use it in GitHub Desktop.
cleanup-angular.sh on mac os
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chmod +x cleanup-angular.sh
./cleanup-angular.sh