Skip to content

Instantly share code, notes, and snippets.

@eliascotto
Last active December 18, 2025 06:44
Show Gist options
  • Select an option

  • Save eliascotto/d12fbeee9b5f79a94e210629d341b6b3 to your computer and use it in GitHub Desktop.

Select an option

Save eliascotto/d12fbeee9b5f79a94e210629d341b6b3 to your computer and use it in GitHub Desktop.
Remove all node_modules folders in a subdirectory
#!/bin/bash
# Check if a folder was passed as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <path-to-folder>"
exit 1
fi
BASE_DIR="$1"
# Find and delete all node_modules directories
echo "Searching for node_modules in: $BASE_DIR"
find "$BASE_DIR" -type d -name "node_modules" -prune | while read -r dir; do
echo "Removing: $dir"
rm -rf "$dir"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment