rsync: Copy Trees Without Copying What Has Not Changed

scp copies the file again. rsync copies the difference. That is the whole reason it exists.

rsync walks a source and a destination and sends what is missing or newer. The trailing slash matters: src/ means the contents, src means the directory itself. Checked on macOS openrsync (protocol 29): -a, -n, --stats, and --delete. Linux usually has GNU rsync. The flags below are the overlap. Do not paste a GNU-only flag and expect openrsync to know it.

install

macOS
# already installed as openrsync. brew install rsync replaces it with GNU rsync
rsync --version
Debian/Ubuntu
# in the default repos
sudo apt install rsync
Fedora
# in the default repos
sudo dnf install rsync
Arch
# in the default repos
sudo pacman -S rsync

examples

# Copy the contents of src into dest. Trailing slash on the source is the contents, not the folder
rsync -a src/ dest/
# Dry run. Prints the plan and changes nothing
rsync -a -n src/ dest/
# Same copy, plus a count of files and bytes
rsync -a --stats src/ dest/
# Make dest match src, including deletions. Read the dry run first
rsync -a -n --delete src/ dest/

pro tip

Run the same command with -n once before you add --delete. The dry run is the review. A trailing slash you did not mean is how a destination loses files.

honest limits

This page was checked on macOS openrsync, not GNU rsync. Flags like --info=stats2 are GNU-only and will error here. --delete removes files in the destination that are not in the source. That is the feature, and it is also how you wipe a directory. rsync is not a backup until the destination is a different disk and you have tested a restore.