rsync Command

The rsync command is a powerful and versatile command-line utility for synchronizing files and directories between two locations, either locally or remotely. It's widely used for backups, mirroring, and efficient data transfer due to its delta-transfer algorithm, which only transfers the differences between files.

Syntax

rsync [OPTION]... SOURCE [DESTINATION]

Description

rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from a remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit a wide range of flexible transfer modes.

Key features include:

  • Efficient delta-transfer algorithm (only sends changed parts of files)
  • Preserves permissions, ownership, timestamps, and symbolic links
  • Supports local and remote synchronization (via SSH or rsync daemon)
  • Can be used for backups, mirroring, and incremental transfers

Common Options

Option Description
-a, --archive Archive mode; equals -rlptgoD (recursive, links, perms, times, group, owner, devices)
-v, --verbose Increase verbosity
-z, --compress Compress file data during the transfer
-h, --human-readable Output numbers in a human-readable format
--delete Delete extraneous files from destination dirs (removes files in destination that are not in source)
-r, --recursive Recurse into directories
-u, --update Skip files that are newer on the receiver
-P Equivalent to --partial --progress (show progress during transfer)

Examples

Synchronize local directories

rsync -av /path/to/source/ /path/to/destination/

Synchronizes the contents of 'source' directory to 'destination' directory, preserving attributes.

Synchronize local to remote via SSH

rsync -avz /path/to/local/ user@remote_host:/path/to/remote/

Copies files from local to remote, compressing data during transfer.

Synchronize remote to local via SSH

rsync -avz user@remote_host:/path/to/remote/ /path/to/local/

Pulls files from remote to local, compressing data during transfer.

Delete files in destination that are not in source

rsync -av --delete /path/to/source/ /path/to/destination/

Synchronizes directories and deletes files in destination that are not present in source.

Show progress during transfer

rsync -avP /path/to/source/ /path/to/destination/

Synchronizes directories and shows progress for each file.

See also