Skip to content

Instantly share code, notes, and snippets.

@x1unix
Created June 16, 2021 14:11
Show Gist options
  • Save x1unix/c1c138bece8ff1e84505e64a97b3d218 to your computer and use it in GitHub Desktop.
Save x1unix/c1c138bece8ff1e84505e64a97b3d218 to your computer and use it in GitHub Desktop.
Recursive remove node_modules
#!/usr/bin/env bash
set -e
dir_name=$1
node_dir="node_modules"
echo "Removing each node_modules in $dir_name..."
rm_node_modules() {
dir=$1
echo ":: Inspecting '$dir'..."
if [ -d "$dir/$node_dir" ]; then
rm -rf -v "$dir/$node_dir";
fi
for childdir in $dir/*; do
echo ":: Checking $childdir..."
if [ -d "$childdir" ]; then
rm_node_modules "$childdir"
fi
done
}
if [ ! -d "$dir_name" ]; then
echo "Error: not a dir - $dir_name"
exit 1
fi
rm_node_modules $dir_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment