Project Maintenance Scripts
Cleanup Plan
Build a Safe Delete Command
Maintenance scripts often remove generated files, but the planned command should be visible before it runs.
Program
Play the script to choose a retention window and see the cleanup command it would run.
cleanup_plan.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash
keep_days=7
cache_dir="build-cache"
command="find $cache_dir -mtime +$keep_days -delete"
echo "$command"
#!/usr/bin/env bash
keep_days=14
cache_dir="build-cache"
command="find $cache_dir -mtime +$keep_days -delete"
echo "$command"
keep_days ← 7
3keep_days=74cache_dir="build-cache"values this step7keep_dayscache_dir ← build-cache
3keep_days=74cache_dir="build-cache"5command="find $cache_dir -mtime +$keep_days -delete"values this stepbuild-cachecache_dircommand ← find build-cache -mtime +7 -delete
4cache_dir="build-cache"5command="find $cache_dir -mtime +$keep_days -delete"6echo "$command"values this stepfind build-cache -mtime +7 -deletecommandbuild-cachecache_dir7keep_daysecho "$command"
5command="find $cache_dir -mtime +$keep_days -delete"6echo "$command"outputfind build-cache -mtime +7 -deletevalues this stepfind build-cache -mtime +7 -deletecommand
keep_days ← 14
3keep_days=144cache_dir="build-cache"values this step14keep_dayscache_dir ← build-cache
3keep_days=144cache_dir="build-cache"5command="find $cache_dir -mtime +$keep_days -delete"values this stepbuild-cachecache_dircommand ← find build-cache -mtime +14 -delete
4cache_dir="build-cache"5command="find $cache_dir -mtime +$keep_days -delete"6echo "$command"values this stepfind build-cache -mtime +14 -deletecommandbuild-cachecache_dir14keep_daysecho "$command"
5command="find $cache_dir -mtime +$keep_days -delete"6echo "$command"outputfind build-cache -mtime +14 -deletevalues this stepfind build-cache -mtime +14 -deletecommand
retention
A retention window says how long generated files should be kept.
cleanup plan
Printing the command first makes destructive maintenance easier to review.
side-effect boundary
This lesson builds command text without deleting anything.