Core rsync Syntax
rsync [options] source destinationBack to top
Practical rsync Examples
Use rsync to copy files from one local directory to another local directory:
rsync -av /source/directory/ /destination/directory/Use rsync to copy files from a remote server to a local directory over SSH:
rsync -avz user@server:/remote/directory/ /local/directory/Use rsync to copy files from a local directory to a remote server over SSH
rsync -avz /local/directory/ user@server:/remote/directory/Use rsync to copy a large file (sql dump, iso, etc) and show progress
rsync -av --progress database_dump.sql /backup/Use rsync to copy all files from a directory excluding a file extension (.tmp)
rsync -av --exclude="*.tmp" /source/directory/ /destination/directory/Back to top
Common rsync Options
| Option | Description |
|---|---|
-a | Archive mode. Recursively copies files while preserving permissions, timestamps, ownership, and symlinks. |
-v | Verbose. Shows detailed output of the transfer process. |
-z | Compresses file data during transfer to reduce bandwidth usage. |
--progress | Displays progress information for each file during transfer. Useful for large files. |
--delete | Removes files from the destination that no longer exist in the source, creating an exact copy. |
--dry-run | Simulates the transfer and shows what would happen without making changes. |
--exclude | Excludes specific files or directories from being transferred. |
--partial | Keeps partially transferred files if the transfer is interrupted. |
--checksum | Compares files using checksums instead of timestamps and size. Slower but more precise. |
-e | Specifies the remote shell to use, typically SSH or a custom port. |
Other Notes
The trailing slash matters. /source/ copies the contents of the directory, while /source copies the directory itself.
The rsync command works by computing rolling checksums of file blocks. If only part of a file changes, rsync transfers just the changed blocks rather than the entire file. That design makes it extremely efficient for large sets of files.
The tool dates back to 1996, which in internet years is roughly the Cambrian explosion. Yet it remains one of the most efficient file synchronization tools ever written. Many modern backup systems and deployment tools quietly run rsync under the hood.
Back to top