Home·Terminal commands

rsync

Files and directories

Usage

rsync -av [source]/ [dest]/

Copies only the differences between two trees, locally or over ssh; a trailing slash on the source means its contents, and leaving it off nests the directory one level deeper.

Common flags

FlagMeaning
-aArchive: recursive, keeping permissions, times and symlinks
-vList what is transferred
-zCompress while it travels
-PShow progress and keep partial files so a transfer can resume
--deleteRemove files in the destination that are gone from the source
-nDry run: print what would happen and change nothing
--excludeSkip paths matching a pattern
-eChoose the remote shell, as in -e "ssh -p 2222"

Examples

rsync -avP big.iso server:/data/

Copies with progress, and can resume later.

rsync -av --delete site/ /backup/site/

Makes the backup an exact mirror.

rsync -avn src/ dst/

Dry run first; nothing is written.

Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does rsync do?

Copies only the differences between two trees, locally or over ssh; a trailing slash on the source means its contents, and leaving it off nests the directory one level deeper.

Q. How do I type it?

rsync -av [source]/ [dest]/ — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

8 are listed here; the full set is in man rsync. This command sits under Files and directories.

Related commands

man page: man rsync