Created
December 15, 2023 10:14
-
-
Save a-c-m/ad14a7ac60732fe1fee663eec3b51507 to your computer and use it in GitHub Desktop.
Revisions
-
a-c-m created this gist
Dec 15, 2023 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ #!/bin/bash # Find all top-level node_modules directories and calculate their total size total_size=0 for dir in $(find . -name "node_modules" -type d -not -path "*/node_modules/*"); do size=$(du -sk "$dir" | cut -f1) total_size=$(($total_size + $size)) done # Convert total size to human-readable format total_size_human=$(awk "BEGIN { printf \"%.2f\", $total_size/1024/1024 }") # Print total size printf "Total node_modules size is %.2f GB, across %d directories.\n" $total_size_human $(find . -name "node_modules" -type d -not -path "*/node_modules/*" | wc -l) # Find all top-level node_modules directories and print their size and percentage of total for dir in $(find . -name "node_modules" -type d -not -path "*/node_modules/*"); do size=$(du -sk "$dir" | cut -f1) percentage=$(echo "scale=2; $size / $total_size * 100" | bc) size_human=$(awk "BEGIN { printf \"%.2f\", $size/1024/1024 }") printf "%0.0f%% - %s (%.2f GB)\n" $percentage $dir $size_human done