CalcSnippets Search
DevOps 1 min read

`rsync --delete` Is the Flag You Need When Your Deploy Target Keeps Collecting Stale Files Like a Junk Drawer

A practical guide to `rsync --delete` for making destination directories actually match the source instead of silently accumulating obsolete files.

Why this flag matters: many file sync workflows copy new files correctly but quietly leave old files behind, which is how deploy targets become mysterious over time.

If you want the destination to actually mirror the source, rsync --delete is often the missing flag.

The basic form

rsync -av --delete build/ server:/var/www/app/

This says: copy what exists in build/, and also remove destination files that no longer exist in the source.

That matters because stale files cause real problems:

  1. old assets still served
  2. deleted templates lingering
  3. confusing mixed-version deploys
  4. harder debugging after refactors

Why people hesitate to use it

Because deletion is scary, and rightly so.

That is why preview-first discipline matters. Start with a dry run:

rsync -av --delete --dry-run build/ server:/var/www/app/

Then inspect what would change before removing the preview flag.

This is the right pattern:

  1. preview
  2. inspect
  3. run for real

Final recommendation

If your deploy target keeps accumulating stale files, look at rsync --delete with --dry-run first. It is one of the cleanest ways to make destination state actually match source state instead of slowly turning into operational clutter.

Sources

Keep reading

Related guides