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
| Flag | Meaning |
|---|---|
| -a | Archive: recursive, keeping permissions, times and symlinks |
| -v | List what is transferred |
| -z | Compress while it travels |
| -P | Show progress and keep partial files so a transfer can resume |
| --delete | Remove files in the destination that are gone from the source |
| -n | Dry run: print what would happen and change nothing |
| --exclude | Skip paths matching a pattern |
| -e | Choose 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