rsync — Efficient file and directory sync, transferring only changed parts across all 5 shells
Equivalents in every shell
Bashunix
rsync -av src/ dest/Zshunix
rsync -av src/ dest/Fishunix
rsync -av src/ dest/PowerShellwindows
robocopy src dest /E /Z`rsync` is not native to Windows — `robocopy` is the closest built-in (resumable, recursive, NTFS-aware) but uses completely different flag names. For real rsync install via WSL, Cygwin, or Git Bash.
cmd.exewindows
robocopy src dest /E /Z`robocopy` (Windows-bundled since Vista) is the cmd-side replacement. `/E` copies subdirectories including empty, `/Z` enables resumable mode.
Worked examples
Sync a local directory to a remote host over SSH
Bash
rsync -avz src/ user@host:/var/www/Fish
rsync -avz src/ user@host:/var/www/Mirror: make dest match src exactly, deleting extras
Bash
rsync -av --delete src/ dest/Fish
rsync -av --delete src/ dest/PowerShell
robocopy src dest /MIRcmd.exe
robocopy src dest /MIRDry-run: preview what would change without copying
Bash
rsync -avn --delete src/ dest/Fish
rsync -avn --delete src/ dest/PowerShell
robocopy src dest /MIR /LGotchas
- Trailing slash on the source matters: `rsync -a src/ dest/` copies the *contents* of `src` into `dest`. `rsync -a src dest/` copies the directory `src` itself into `dest` (yielding `dest/src/...`). Burn this in.
- `--delete` is destructive — it removes files in `dest` that don't exist in `src`. Always pair with `-n` (dry-run) on the first invocation.
- rsync chooses transfer mode by argument shape: if either side contains a colon it transfers over SSH; otherwise it is local. To force SSH against `host:path` with a non-default port, use `rsync -e "ssh -p 2222"`.
- robocopy is NOT a drop-in for rsync. It has no delta-transfer (whole-file copy only), no SSH, and a totally different flag scheme (`/MIR` vs `--delete`, `/Z` vs `--partial`). For network sync on Windows, prefer rsync via WSL.
- rsync's exit code is non-zero (e.g. 23) when *any* file failed — even if 999 of 1000 succeeded. Robocopy's exit codes are bitmasked (1 = files copied, 2 = extra files, 4 = mismatched) — codes ≤ 7 are success.
WSL & PowerShell Core notes
pwshPowerShell Core does not ship rsync. On Linux/macOS pwsh, the system `rsync` is available. On Windows pwsh, install via `winget install cwRsync` / WSL / Cygwin, or fall back to `robocopy` for local syncs.
WSLWSL `rsync` works fine — including for `wsl-host → linux-host` transfers. Syncing `/mnt/c/...` is supported but every metadata-preserving flag (`-p`, `--owner`, `--group`) only works if `metadata` is enabled in `/etc/wsl.conf`; otherwise rsync prints harmless "failed to set permissions" warnings.