Back to lessons

Dangerous Commands

Print a Dry-Run Removal Script

You have cleanup candidates and need a human-reviewable removal plan instead of executing deletion directly from find.

Command

find /lab/disk-inode-cleanup/var/tmp/uploads -xdev -type f -mtime +7 -printf 'rm -i -- %p\n'

What changed

Nothing changes. The command prints interactive rm commands as text and does not execute them.

Danger

caution

When to use it

Use when turning a candidate list into a reviewed cleanup plan for a small, well-understood path.

When not to use it

Do not pipe generated removal commands into a shell; review, quote, and execute intentionally if cleanup is approved.

Undo or recovery

No undo needed for the dry run. If a printed command is later executed, restore from backup or the source system.

Expected output

One printed rm -i command per old cleanup candidate.

demo script

Disposable terminal steps

  1. find /lab/disk-inode-cleanup/var/tmp/uploads -xdev -type f -mtime +7 -printf '%TY-%Tm-%Td %p\n' | sort
  2. find /lab/disk-inode-cleanup/var/tmp/uploads -xdev -type f -mtime +7 -printf 'rm -i -- %p\n'

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ find /lab/disk-inode-cleanup/var/tmp/uploads -xdev -type f -mtime +7 -printf '%TY-%Tm-%Td %p\n' | sort
2026-06-01 /lab/disk-inode-cleanup/var/tmp/uploads/old-export.tar
::exit-code::0
$ find /lab/disk-inode-cleanup/var/tmp/uploads -xdev -type f -mtime +7 -printf 'rm -i -- %p\n'
rm -i -- /lab/disk-inode-cleanup/var/tmp/uploads/old-export.tar
::exit-code::0

YouTube Short

Print cleanup commands first.

If deletion is on the table, print the exact rm commands first. Review the plan before anything touches the files.

LinkedIn hook

The reviewable cleanup command is the one you print before you run.

Question: Do you review generated cleanup commands before executing them?

experiments

A/B tests to run

Metric: save_rate

A: Print the cleanup plan first.

B: Never pipe cleanup straight into a shell.