#!/bin/bash set -e # Find all directories that contain a migrations folder (Django apps) while IFS= read -r -d '' dir; do app_dir="${dir%/migrations}" app_name="$(basename "$app_dir")" echo "clean migrations $app_name ..." find "$dir" -maxdepth 1 -type f -name "*.py" ! -name "__init__.py" -delete find "$dir" -maxdepth 1 -type f -name "*.pyc" -delete find "$dir" -maxdepth 1 -type f -name "*.pyc" -delete find "$dir" -maxdepth 1 -type f -name "*.py~" -delete find "$dir" -maxdepth 1 -type f -name "*.pyo" -delete find "$dir" -maxdepth 1 -type f -name "*.swp" -delete done < <(find . -type d -name migrations -print0) echo "clear all." #run # ./clear_migrations.sh