Back to guides

linux troubleshooting guide

Rsync Dry Run: Preview Copy and Delete Changes

A dry run turns a risky sync into reviewable output. That matters most when `--delete`, backups, or deployment targets are involved.

Problem

You need to mirror two directories, but the command may copy the wrong level, delete target files, or overwrite useful data.

First rule

Run the exact rsync command with dry-run enabled before running it for real.

Audience

developers, backup operators, self-hosters, and Linux certification students practicing file synchronization

Cert context

Unofficial command practice for file management, backups, path handling, and administrative caution.

quick start

Safe first commands

  1. rsync -avhn --delete ./source/ ./backup/
  2. rsync -ani --delete ./source/ ./backup/
  3. rsync -avhn --delete ./source/ ./backup/ | grep '^deleting'

Use dry run on the final command shape

A dry run only protects you if it matches the real command. Keep the same source, destination, filters, delete flags, and trailing slashes.

  1. rsync -avhn --delete ./source/ ./backup/

Itemize output for review

The `-i` flag adds change codes that are useful when you need to review what would be created, updated, or removed.

  1. rsync -ani --delete ./source/ ./backup/

Pay attention to trailing slashes

`source/ target/` copies the contents of source into target. `source target/` copies the source directory itself under target. That distinction changes the resulting tree.

  1. rsync -avhn source/ target/
  2. rsync -avhn source target/

Review deletes separately

When `--delete` is present, scan delete candidates before doing anything irreversible.

  1. rsync -avhn --delete ./source/ ./backup/ | grep '^deleting'

triage logic

How to read the result

dry-run output deletes files you expected to keep

The source may be incomplete, filters are wrong, or the source and target are reversed.

Next: Stop and inspect paths before running the real sync.

dry-run output creates an extra nested directory

The trailing slash shape is probably wrong for your intended layout.

Next: Test source path variants against a disposable directory.

dry-run output is too long to review

The change is too large for a casual command run.

Next: Write output to a file and review summary counts before execution.

safety notes

Slow down here

  • Never run `--delete` against a destination you have not backed up or reviewed.
  • Prefer absolute paths in scripts and scheduled jobs.
  • Log dry-run output for important migrations.

Independent study support

These guides are cert-adjacent practice material, not official training, endorsement, exam dumps, or real exam questions.

related lessons

Command cards