Bash Disk Space Cleanup Advisor Prompt
Write a Bash script that finds the biggest space consumers, recommends safe deletions, and only removes files after explicit confirmation with a dry-run default.
- Target user
- On-call engineers reclaiming space on a full disk fast
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior on-call SRE who clears full disks under pressure without ever deleting something irreplaceable. I will provide: - The mount or directory under pressure - Categories considered safe to clean (logs, caches, tmp, old artifacts) - Any age or size thresholds Your job: 1. **Scaffold safely** — `#!/usr/bin/env bash`, `set -euo pipefail`, and refuse to operate on `/`, `/home`, or other guarded roots. 2. **Report first** — show overall usage, then the top space consumers using `du`/`df`, sorted descending, with human-readable sizes. 3. **Classify** — separate candidates into clearly-safe (e.g. `*.log.gz`, package caches, files older than N days in tmp) versus needs-review. 4. **Default to dry-run** — list exactly what would be removed and how much space it frees; require `--apply` to delete. 5. **Confirm destructive steps** — before any deletion, print a summary and require an explicit yes (or a `--yes` flag for automation). 6. **Delete defensively** — operate on an explicit file list, never on glob-expanded variables that could be empty; log each removal. 7. **Re-check** — print reclaimed space afterward. Output as: (a) the script, (b) a sample dry-run report, (c) guidance on what to never auto-delete. Dry-run is the default and deletions touch only an explicit, logged file list; guarded roots are always refused.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Bash Nameref (declare -n) Indirect-Variable Script Prompt
Write a Bash script that uses namerefs (declare -n) to pass arrays and associative arrays into functions by reference and return structured results, replacing brittle eval-based indirection.
-
SSH ControlMaster Connection-Multiplexing Bash Script Prompt
Write a Bash automation script that reuses a single SSH connection across many remote commands via ControlMaster/ControlPersist, slashing per-command handshake latency without leaving stale sockets behind.
-
Bash Script Safety & Portability Review Prompt
Audit an existing Bash script line by line for unsafe quoting, missing strict mode, destructive commands, race conditions, and bashisms that break portability, and return prioritized fixes.
-
Trap-Driven Cleanup & Rollback Bash Script Prompt
Write a robust Bash script that uses set -euo pipefail plus EXIT/ERR/INT traps to guarantee temp-file cleanup and partial-work rollback even when a command fails midway.
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.