The Go Blog

clean node_modules directories

bantana
1 January 2018

find node_modules directories

touch ~/bin/findnodedir.sh

#!/usr/bin/env bash
find . -maxdepth 2 -name node_modules  -type d

with bash "rm -rf" clean

$ findnodedir.sh|xargs -I{} rm -rf {}

another clnode.sh

#!/usr/bin/env bash
echo
echo "clean node_modules"
echo

for i in $(find . -name node_modules -type d); do
        if [ $(grep -o "node_modules" <<<"$i" | wc -l) == 1 ]
        then
                echo "$(du -sh $i)"
                read -p "Delete Y/N ? " -n 1 -r
                echo
                if [[ $REPLY =~ ^[Yy]$ ]]
                then
                        rm -r $i
                        echo "deleted"
                fi
        fi
done