Created
July 17, 2025 19:55
-
-
Save tangoabcdelta/315266a7c4bbacac62bd1d48eded8c82 to your computer and use it in GitHub Desktop.
Clear all Node Modules and .git directories recursively
This file contains hidden or 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
#!/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