Skip to content

Instantly share code, notes, and snippets.

@goshki
Last active June 24, 2025 16:13
Show Gist options
  • Save goshki/51b85bf0994bf496e37241ed5f553dcb to your computer and use it in GitHub Desktop.
Save goshki/51b85bf0994bf496e37241ed5f553dcb to your computer and use it in GitHub Desktop.
Bash script to clean up a Unity project directory (removes files and folders that Unity can regenerate when loading the project again)
#!/bin/bash
FOLDERS_TO_DELETE=("Library" "Temp" "obj" "Build" "Builds" "Logs")
FILES_TO_DELETE=("*.sln" "*.csproj")
DRY_RUN=true
if [[ "$1" == "--apply" ]]; then
DRY_RUN=false
fi
if [ "$DRY_RUN" = true ]; then
echo "--- Starting Unity project clean-up in DRY RUN mode (use --apply to perform actual clean-up) ---"
echo "No files or folders will be deleted."
else
echo "--- Starting Unity project clean-up in LIVE mode ---"
echo "WARNING: This script will delete files and folders immediately."
fi
echo "Current directory: $(pwd)"
echo ""
for folder_name in "${FOLDERS_TO_DELETE[@]}"; do
if [ -d "$folder_name" ]; then
if [ "$DRY_RUN" = true ]; then
echo " [DRY RUN] Would delete folder: ./${folder_name}"
else
echo " Deleting folder: ./${folder_name}"
rm -rf "$folder_name"
fi
fi
done
for file_pattern in "${FILES_TO_DELETE[@]}"; do
for file_to_delete in ${file_pattern}; do
if [ -f "$file_to_delete" ]; then
if [ "$DRY_RUN" = true ]; then
echo " [DRY RUN] Would delete file: ./${file_to_delete}"
else
echo " Deleting file: ./${file_to_delete}"
rm -f "$file_to_delete"
fi
fi
done
done
echo ""
if [ "$DRY_RUN" = true ]; then
echo "--- Dry Run Complete! ---"
else
echo "--- Cleanup Complete! ---"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment