Skip to main content

rsync command

Detailed Explanation

rsync is a widely-used utility to keep copies of a file on two computer systems synchronized. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. It is highly favored for backups and mirroring.

Basic Syntax

rsync [OPTION...] SRC... [DEST]

Common Flags/Options

OptionDescription
-v, --verboseIncrease verbosity.
-a, --archiveArchive mode; equals -rlptgoD (preserves permissions, times, symbolic links, etc., and recurses).
-r, --recursiveRecurse into directories.
-z, --compressCompress file data during the transfer.
-PSame as --partial --progress (shows progress bar and keeps partially transferred files).
-e, --rsh=COMMANDSpecify the remote shell to use (e.g., ssh).
--deleteDelete extraneous files from dest dirs (make destination an exact mirror of source).

Real-world Examples

Copy a directory locally, preserving permissions and showing progress:

rsync -av /source/directory/ /destination/directory/

(Note: The trailing slash on /source/directory/ means "copy the contents of this directory". Without it, it copies the directory itself.)

Sync a local directory to a remote server over SSH:

rsync -avz -e ssh /local/dir/ user@remote_host:/remote/dir/

Mirror a directory (deleting files on destination that don't exist on source):

rsync -avz --delete /local/dir/ user@remote_host:/remote/dir/

Show progress for large file transfers:

rsync -avP large_file.iso /destination/