When to use rsync
Use rsync for repeatable file synchronization with an explicit source and destination. Start with a dry run and pay attention to trailing slashes, metadata requirements and whether both endpoints have the necessary tool installed.
Syntax
rsync [PARAMETERS] SOURCE DESTINATIONSquare brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Check sync plan
rsync -avn ./project/ ./project-backup/The planned archive-mode copy is displayed without changing destination files.
Copy directory contents
rsync -av ./project/ ./project-backup/The directory contents are copied while preserving the attributes supported by this account and filesystem.
Send a directory over SSH
rsync -av -e ssh ./project/ deploy@server.example.com:/srv/app/The source contents are transferred to the remote directory through an SSH transport.
Notes and limitations
- A trailing / on the source means copy its contents rather than the directory itself.
- --delete removes extra files at the destination. Inspect a dry run first. rsync must be installed on both ends when using SSH.
Common questions and troubleshooting
Why does a trailing slash change the copied layout?
A slash on a source directory means copy its contents; without it the directory itself can be included. Preview the exact layout before committing.
Does this delete files absent from the source?
Not with these commands. Deletion requires an explicit option; if you later add it, first inspect a dry run and retain a recoverable backup.
Further help
Options vary by version and distribution. Check the installed documentation with this command: man rsync.