rsync Command Builder

Build a correct rsync command without guessing at flag order or quoting. Choose archive mode, compression, delete, dry-run and exclude patterns; add an SSH shell for remote transfers. The builder notes the trailing-slash gotcha on the source path — one of rsync\'s most common footguns — so you know what will actually be copied.

How to use the rsync Command Builder

Enter the source and destination paths. A local path is a filesystem path like /home/user/project/. A remote path uses user@host:/remote/path/ syntax. If a path contains spaces, add quotes manually around it in the output.

Archive mode (-a) is equivalent to -rlptgoD: recursive, preserve symlinks, permissions, timestamps, group, owner and device files. It is the right default for any backup or deployment scenario. Compress (-z) reduces bandwidth but adds CPU overhead — skip it on a LAN.

Delete (--delete) removes files from the destination that no longer exist in the source. This is essential for true mirroring but destructive — always test with Dry run first. Dry run (-n) shows exactly what would be transferred without touching anything.

Enter exclude patterns one per line: *.log, .git, node_modules. Each becomes a separate --exclude='...' argument. The optional SSH field sets the remote shell via -e 'ssh ...' — use this to specify a non-standard port or identity file.

Trailing slash on the source: rsync -a /src/ /dest/ copies the contents of src into dest. rsync -a /src /dest/ (no trailing slash) copies the directory itself, creating /dest/src/. The builder warns you when neither path ends with a slash.

About rsync

rsync (Remote Sync) is a file-copying utility that uses a delta-transfer algorithm: on subsequent runs it compares file checksums and modification times and transfers only the changed bytes rather than entire files. For large directories that change incrementally — build artefacts, media libraries, database dumps — this makes repeated syncs dramatically faster than scp or cp.

rsync can operate locally (source and dest are both local paths), over SSH (one or both paths use user@host: syntax), or via the native rsync daemon protocol (paths starting with ::). The SSH transport is the most common for server deployments because it reuses existing SSH infrastructure and key-based authentication. The -e flag lets you pass custom SSH options, notably a non-standard port (ssh -p 2222) or a specific identity file.

The trailing-slash rule is rsync's most notorious gotcha: rsync /src/ /dest/ syncs the contents of src, while rsync /src /dest/ creates /dest/src/. This asymmetry does not apply to the destination. Understanding this distinction prevents accidentally duplicating directory levels in your target. Combined with --delete, a wrong source path can also delete correct files on the destination — always validate with -n first.

Common use cases

  • Incremental server backups — archive a web root to a backup server over SSH nightly; only changed files are transferred.
  • Deployment pipelines — push a built frontend dist/ to a production server, using --delete to remove stale assets and --exclude to skip source maps.
  • Local directory mirroring — mirror a large photo or dataset directory to an external drive, resuming interrupted transfers with --partial.
  • Cross-server migrations — move a site between hosts by rsyncing files, then replaying database dumps; repeat rsync before DNS cutover to minimise downtime.
  • Bandwidth-constrained transfers — add -z to compress in transit when copying between data centres over metered connections.

Frequently asked questions

What does the trailing slash on the source do?

rsync /src/ /dest/ copies the contents of src into dest — dest becomes a mirror of src. rsync /src /dest/ copies the directory itself, creating /dest/src/. This is the single most common rsync mistake. Add a trailing slash to the source when you want to sync contents, not when you want to copy the folder as a named subdirectory.

Is --delete safe?

It is irreversible on the destination — deleted files are not moved to a trash. Always test with -n (dry run) first and review the output. Consider combining with --backup or --backup-dir to preserve deleted files.

Why is -z (compress) sometimes slower?

Compression adds CPU overhead on both ends. On a fast LAN where bandwidth is not the bottleneck, the compression time exceeds the time saved on transfer. Use -z when the link is slow (remote WAN) or when files compress well (text, logs, source code). Skip it for pre-compressed files (images, videos, zip archives).

How do I exclude multiple patterns?

Enter one pattern per line in the Exclude field. The builder emits a separate --exclude='...' argument for each. You can also use --exclude-from=file.txt to read patterns from a file, useful for large exclusion lists.

How do I specify a different SSH port?

Enter ssh -p 2222 in the SSH field. The builder outputs -e 'ssh -p 2222'. Note rsync uses lowercase -e for the remote shell, not -P. Capital -P is used by scp.