Modern QA2026Practical Script: Test Data Cleanup — tiles
Log inJoin
37 / 55 · 19 Linux & Command Line · Bash Scripting for QA← prev⊞ allnext →☰ Read as one page

5.7Practical Script: Test Data Cleanup

#!/bin/bash
# cleanup-test-data.sh -- Remove test data older than N days
set -euo pipefail

DAYS="${1:-7}"
DIRS=("test-results" "screenshots" "videos" "traces" "coverage")

echo "Cleaning up test artifacts older than $DAYS days..."

for dir in "${DIRS[@]}"; do
    if [ -d "$dir" ]; then
        COUNT=$(find "$dir" -type f -mtime +"$DAYS" | wc -l)
        if [ "$COUNT" -gt 0 ]; then
            echo "  Removing $COUNT files from $dir/"
            find "$dir" -type f -mtime +"$DAYS" -delete
        else
            echo "  $dir/ -- nothing to clean"
        fi
    fi
done

echo "Cleanup complete"