BASH

Automate Cleanup of Project Directories

Efficiently clean up common project artifacts like `node_modules`, `dist`, `build`, and `vendor` directories across multiple subdirectories to free up disk space.

#!/bin/bash

# Directories to clean up
TARGET_DIRS=("node_modules" "dist" "build" "vendor" ".cache" ".parcel-cache" "public/build")

echo "Starting project cleanup..."

# Find and remove specified directories
# Maxdepth limits search depth to avoid going into node_modules themselves
find . -maxdepth 4 -type d \( $(printf -- '-name "%s" -o ' "${TARGET_DIRS[@]}") -false \) -prune -exec echo "Removing {}..." \; -exec rm -rf {} \;

echo "Cleanup complete!"
How it works: This script helps clean up common project-specific directories such as `node_modules`, `dist`, `build`, `vendor`, `.cache`, `.parcel-cache`, and `public/build`. It uses the `find` command to locate these directories up to a depth of 4 and then removes them recursively, helping to free up significant disk space, especially in monorepos or when working with many projects and managing temporary build artifacts.

Need help integrating this into your project?

Our team of expert developers can help you build your custom application from scratch.

Hire DigitalCodeLabs