$linuxjunkies
>

rsync(1)

rsync is a fast, versatile file synchronization tool that efficiently transfers and synchronizes files between local and remote systems.

UbuntuDebianFedoraArch

Synopsis

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

Description

rsync is a utility for efficiently transferring and synchronizing files across computer networks. It uses a delta-transfer algorithm that only sends differences between source and destination, making it much faster than simple copy commands for large files or many changes. rsync works over SSH for security and can mirror entire directory trees while preserving permissions, ownership, and timestamps.

Common use cases include backups, mirroring, incremental transfers, and maintaining synchronized copies across multiple machines. rsync can operate in local mode (file-to-file on the same system) or remote mode (using SSH or rsync protocol) to transfer data to or from another host.

Common options

FlagWhat it does
-a, --archiveArchive mode; same as -rlptgoD, preserves permissions, ownership, times, and recursion
-v, --verboseIncrease verbosity; show files being transferred and summary statistics
-r, --recursiveRecurse into directories; necessary to sync directory trees
-e, --rsh=COMMANDSpecify remote shell to use, typically 'ssh' or 'ssh -p 2222' for custom ports
--deleteDelete files on destination that don't exist on source (dangerous; use with care)
-z, --compressCompress file data during transfer; saves bandwidth over slow links
--progressShow progress for each file and a summary total progress bar
-PSame as --partial --progress; keeps partial files and shows progress
--exclude=PATTERNExclude files matching PATTERN; can be used multiple times
-u, --updateSkip files on destination that are newer than source files
--bwlimit=KBPSLimit bandwidth used in kilobytes per second
-n, --dry-runShow what would be transferred without actually doing it

Examples

Archive and verbosely sync a local directory tree, preserving all attributes

rsync -av /local/path/ /backup/path/

Sync local directory to remote host over SSH with compression

rsync -avz -e ssh /local/path/ [email protected]:/remote/path/

Sync remote directory to local system over SSH (pull operation)

rsync -avz -e ssh [email protected]:/remote/path/ /local/path/

Mirror source to destination, removing files in destination that no longer exist in source

rsync -av --delete /source/ /destination/

Sync directory excluding log files and .git directories to remote host

rsync -avz --exclude='*.log' --exclude='.git' /source/ user@host:/backup/

Transfer large files with progress display, limiting bandwidth to 1 MB/s

rsync -avP --bwlimit=1000 /large/dataset/ user@remote:/storage/

Perform a dry-run to preview what would be synced without making changes

rsync -avn /source/ /destination/

Sync and delete extraneous files on destination after transfer completes

rsync -ave ssh --delete-after /source/ user@host:/dest/

Related commands