find . -name "node_modules" -type d -prune -print | xargs du -chs
find . -type d -name node_modules | grep -v node_modules.*node_modules | tr '\n' '\0' | xargs -0 du -sch
#!/bin/bash | |
# | |
# This script will remove all node modules | |
# | |
# Author: Lafif Astahdziq | |
# https://lafif.me | |
# | |
FOLDER_ROOT=${1:-.} # default to current directory | |
echo "---- Check Folders -----"; | |
# Check and count node modules directories | |
if [[ $(find ${FOLDER_ROOT} -name "node_modules" -type d -prune | wc -l) -eq 0 ]]; then | |
echo "No node_modules found!" | |
else | |
find ${FOLDER_ROOT} -name "node_modules" -type d -prune -print | xargs du -chs | |
# Let user confirm delete | |
read -p "Delete all folders (y/n)? " -n 1 -r CONFIRM | |
echo # move to a new line | |
if [[ $CONFIRM =~ ^[Yy]$ ]] | |
then | |
echo "Removing.."; | |
find ${FOLDER_ROOT} -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \; | |
fi | |
fi |