Skip to content

Instantly share code, notes, and snippets.

@tangoabcdelta
Created July 17, 2025 19:55
Show Gist options
  • Save tangoabcdelta/315266a7c4bbacac62bd1d48eded8c82 to your computer and use it in GitHub Desktop.
Save tangoabcdelta/315266a7c4bbacac62bd1d48eded8c82 to your computer and use it in GitHub Desktop.
Clear all Node Modules and .git directories recursively
#!/bin/bash
# Set permission for this file: chmod +x file-name.sh
# Function to perform the required actions in each directory
function process_directory() {
local target_dir="$1"
if [[ ! -d "$target_dir" ]]; then
echo "Error: Directory $target_dir does not exist."
return
fi
echo "Searching and deleting all node_modules and .git directories under $target_dir..."
# Find and delete all node_modules directories
find "$target_dir" -type d -name "node_modules" -prune -exec rm -rf '{}' +
# Find and delete all .git directories
find "$target_dir" -type d -name ".git" -prune -exec rm -rf '{}' +
echo "Cleanup complete for $target_dir."
echo
}
# Main script execution
parent_directory="/Users/$USER/Documents/Projects/UI"
# Check if the parent directory exists
if [[ ! -d "$parent_directory" ]]; then
echo "Error: The parent directory does not exist."
exit 1
fi
# Loop through each sub-directory in the parent directory
for directory in "$parent_directory"/*; do
if [[ -d "$directory" ]]; then
process_directory "$directory"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment