Русский flag Русский

All Posts

Safe Find & Replace: How Not to Break Binaries

2025-12-30

When working on real projects (CDN change, migration, refactor) you often need to bulk-replace one URL with another.

At first glance the task seems trivial: sed -i 's|old|new|g' **/* — and done.

In reality that approach is Russian roulette.

A careless replacement leads to:

  • 💀 Corruption of binary files (images, pdf, archives);
  • 📉 Garbage in git history (binaries marked as changed);
  • 🚫 Inability to cleanly roll back if a backup wasn’t made.

In this note we’ll cover a production-grade algorithm: change only text, don’t touch binaries, make a targeted backup.