
Measure before you delete
What you will learn
- Why the obvious tidy up is usually the wrong one
- How ten minutes of measuring found three culprits out of sixty suspects
- The one habit that lets you be wrong without losing anything
The instruction was reasonable and I nearly followed it. A pile of leftover backup files had built up across a project, something had become bloated, and the obvious move was to clear them out. Roughly sixty items. A single command would have done it.
Instead I spent ten minutes measuring which of them were actually causing the problem.
The answer was three. Not three categories. Three items, out of about sixty, were responsible for all of it.
Why those three
The reason turned out to be a detail nobody could have guessed from the outside.
The three that mattered were folders, and the files inside them had kept their normal names, so everything else happily picked them up as though they were real working files. The other fifty seven were individual files whose names ended in a backup marker. Nothing was reading those. They had never contributed to the problem and never would.
Among those fifty seven innocent files: a backup of a credentials file, and a stack of undo copies of something I had been carefully revising all week.
The exact things you want during an emergency. All deleted, for no benefit, chasing a problem they were not causing.
The trap, precisely stated
The naive cleanup was not merely imprecise. It was precisely backwards. It would have left the actual cause untouched if I had got the pattern slightly wrong, while destroying the safety net I would need the next time something broke.
And it would have looked like a success, because the number of files would have dropped dramatically and the underlying problem would have been quietly fixed by the three items I happened to catch.
A doctor treating pain by removing everything in the general area. The pain probably stops. So does a great deal of other useful function, and nobody learns anything about what was actually wrong.
Why this is a rule and not a preference
Measuring is cheap, reversible, and takes minutes. Deleting is instant, feels productive, and cannot be undone.
When one option is cheap and reversible and the other is fast and permanent, do the cheap reversible one first, every time. You will occasionally waste ten minutes. You will never lose the file you needed.
The habit that pairs with it
Do not delete. Move.
Relocate the offending items somewhere out of the way. The problem is solved identically, because whatever was picking them up no longer sees them, and if you measured wrong you simply move them back.
Deleting buys you disk space. Moving buys you the same outcome plus the ability to be wrong.
In the end I moved three folders out of the way and left all fifty seven files exactly where they were. The bloat went away. The credentials backup and the undo copies are still sitting there, useless and harmless, waiting for the day one of them saves me.
Measure what is actually costing you before you remove anything. The obvious cleanup is usually the wrong one.
How to work out which specific things are causing a problem before you touch them, and how to remove things in a way you can undo. The examples are about files, but the method works for anything you can measure one item at a time.
1. Write down what you are actually trying to reduce
What to do: not "clean up the old files". Name the measurable thing: disk space used, items being looked at, how long a job takes.
Why: if you cannot name a number, you cannot tell afterwards whether you helped. Take the reading before touching anything.
scan_count_before=$(your_tool --count)
2. Work out how much each candidate accounts for
What this does: shows the size of each thing you were about to delete, biggest first.
Why it is the whole technique: it usually takes one command, and it answers the question you were about to guess at.
du -sh ./*.bak* 2>/dev/null | sort -rh | head -20
3. Look at the distribution, not the list
Almost always a small number of items account for nearly everything. Find that cut off. If the top three are ninety something percent of your number, you have your answer and the rest is noise.
4. Ask why those items are different
What these do: separate the candidates into folders and individual files.
Why it matters: do not stop at which. Understanding why the guilty ones are guilty tells you whether it will happen again. In my case, folders get walked into and their contents keep ordinary names. Individual files with a backup marker were skipped entirely.
find . -maxdepth 1 -name "*.bak*" -type d # these get scanned
find . -maxdepth 1 -name "*.bak*" -type f # these never were
5. Check what the sweep would have taken
What these do: the first lists everything a delete would touch, without deleting anything. The second searches that list for the words that should stop you.
What to look for: credentials, backups of live settings, and recent undo copies.
Read the output properly. This is the step that saved me.
find . -name "*.bak*" -print # no deleting yet
find . -name "*.bak*" | grep -iE 'env|secret|cred|key|conf'
6. Move, do not delete
What these do: make a holding area, then move only the items you actually measured, one at a time.
Why one at a time: so you can check each one. Same result as deleting, fully reversible.
mkdir -p ../quarantine/$(basename "$PWD")
mv -v ./that-one-directory ../quarantine/$(basename "$PWD")/
7. Measure again and compare
What this does: takes the same reading as step one and shows both numbers together.
If the number did not move as you predicted: your reasoning was wrong, and because you moved rather than deleted, you can put everything back.
scan_count_after=$(your_tool --count)
echo "before $scan_count_before -> after $scan_count_after"
8. Leave the innocent ones alone
Resist tidying the fifty seven. They cost you nothing, and one of them is the file you will want at two in the morning.
Tidiness is not a measurement, and it is a poor reason to destroy your way back.
Related: the world-readable credentials backup in the guide on where passwords really leak from came out of exactly this pile, which is the other reason to read the list before deleting it.
This page in the original Kyber Cypher voice: Measure before you delete