Back to top

Core rsync Syntax 

rsync [options] source destination
Back 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

OptionDescription
-a

Archive mode. Recursively copies files while preserving permissions, timestamps, ownership, and symlinks.

rsync -a /src/ /dest/
-v

Verbose. Shows detailed output of the transfer process.

rsync -av /src/ /dest/
-z

Compresses file data during transfer to reduce bandwidth usage.

rsync -avz /src/ user@server:/dest/
--progress

Displays progress information for each file during transfer. Useful for large files.

rsync -av --progress largefile.sql /dest/
--delete

Removes files from the destination that no longer exist in the source, creating an exact copy.

rsync -av --delete /src/ /dest/
--dry-run

Simulates the transfer and shows what would happen without making changes.

rsync -av --dry-run /src/ /dest/
--exclude

Excludes specific files or directories from being transferred.

rsync -av --exclude="node_modules" /src/ /dest/
--partial

Keeps partially transferred files if the transfer is interrupted.

rsync -av --partial largefile.sql /dst/
--checksum

Compares files using checksums instead of timestamps and size. Slower but more precise.

rsync -avc /src/ /dest/
-e

Specifies the remote shell to use, typically SSH or a custom port.

rsync -av -e "ssh -p 2222" /src/ user@server:/dest/
Back to top

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