CFG-08 · Backup & transfer

rsync command builder

Pick the flags you want, see a plain-English explanation of each one, and get the exact command — including the trailing-slash difference that changes what actually gets copied.

--delete deletes. Anything present at the destination but not at the source is removed permanently. Run once with -n (dry run) first and read the output before running for real.

Command


  

The trailing slash that changes what gets copied

A trailing slash on the source path means "copy the contents of this directory"; no trailing slash means "copy this directory itself, nested one level deeper at the destination." rsync -a ./data/ dest/ and rsync -a ./data dest/ produce genuinely different results — the first copies files directly into dest/, the second creates dest/data/. This is the single most common rsync surprise.

Why a dry run matters more here than almost any other command

-n runs the exact same matching logic as a real transfer and prints what it would do, without touching anything — the closest thing to a safety net rsync has, especially paired with --delete, which is the one flag on this page capable of permanently removing files at the destination.

Further reading: Why Backups Fail When You Need Them Most — the gap between "the backup job ran" and "the backup actually works," and how to close it.
What does the trailing slash on the source actually do?

src/ (with slash) copies the directory's contents into the destination; src (no slash) copies the directory itself as a new subdirectory of the destination. Forgetting this is the most common reason rsync output ends up one level deeper (or shallower) than expected.

Is --delete safe to use?

It's safe when the destination is meant to be an exact mirror of the source and nothing else — run a dry run (-n) first to see exactly what it would remove. It's not safe if the destination has files you've added independently that aren't in the source; those get deleted too.

Do I need -e ssh for a local-to-local copy?

No — only include it when source or destination is a remote user@host:/path location. For two local paths on the same machine, rsync doesn't need SSH at all.