Last active
January 25, 2017 17:24
-
-
Save maxclaus/6d1b0f02d4cd5784cfdd7cb08a46fe8f to your computer and use it in GitHub Desktop.
Remove all node_module folders recursively. Useful to free up disk space by removing the node_module from those projects you have not used for a while.
This file contains 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
# Simple version using only "find" | |
find . -name "node_modules" -type d -prune -exec rm -rf '{}' + |
This file contains 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
# More helpful version with some log messages and with option of dry mode | |
# Usage: | |
# MODE: DRY | |
# sh remove-node_module-recursively-2.sh ~/my-path-with-many-projects | |
# MODE: REMOVE | |
# sh remove-node_module-recursively-2.sh ~/my-path-with-many-projects remove | |
REMOVE_PATH=$1 | |
MODE=$2 | |
echo "Removing all node_modules from $REMOVE_PATH" | |
if [ "$MODE" != "remove" ]; then | |
echo "-- DRY MODE --" | |
fi | |
for line in $(find $REMOVE_PATH -name "node_modules" -type d -prune); do | |
found=`echo "$line" | grep -o node_modules | wc -l` | |
if [ $found -eq 1 ]; then | |
echo "-> $line" | |
if [ "$MODE" = "remove" ]; then | |
echo "Removing..." | |
rm -rf "$line" | |
else | |
echo "Skip (dry mode enabled)" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment