rsync
Quick Reference
Command Name:
rsync
Category:
file transfer
Platform:
Linux/Unix
Basic Usage:
Common Use Cases
- 1
File synchronization
Keep directories in sync with minimal data transfer using delta algorithm
- 2
Remote backups
Create and maintain backups on remote servers securely over SSH
- 3
Website mirroring
Create exact copies of websites or directory structures
- 4
Large file transfers
Transfer large files efficiently with the ability to resume interrupted transfers
Syntax
rsync [OPTION]... SRC [SRC]... DEST rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST rsync [OPTION]... [USER@]HOST:SRC [DEST]
Options
Option | Description |
---|---|
-v, --verbose | Increase verbosity |
-a, --archive | Archive mode (equivalent to -rlptgoD) |
-r, --recursive | Recurse into directories |
-b, --backup | Make backups (see --suffix & --backup-dir) |
--backup-dir=DIR | Make backups into hierarchy based in DIR |
-z, --compress | Compress file data during the transfer |
-h, --human-readable | Output numbers in a human-readable format |
--progress | Show progress during transfer |
--partial | Keep partially transferred files |
-n, --dry-run | Perform a trial run with no changes made |
-e, --rsh=COMMAND | Specify the remote shell to use |
--delete | Delete extraneous files from destination directories |
--exclude=PATTERN | Exclude files matching PATTERN |
--include=PATTERN | Don't exclude files matching PATTERN |
-P | Same as --partial --progress |
--ignore-existing | Skip updating files that exist on receiver |
--size-only | Skip files that match in size |
--update, -u | Skip files that are newer on the receiver |
--stats | Give some file-transfer stats |
--checksum, -c | Skip based on checksum, not mod-time & size |
Archive Mode (-a) Components:
Option | Description |
---|---|
-r | Recursive (copy directories) |
-l | Copy symlinks as symlinks |
-p | Preserve permissions |
-t | Preserve modification times |
-g | Preserve group |
-o | Preserve owner (super-user only) |
-D | Preserve device files and special files |
Examples
How to Use These Examples
The examples below show common ways to use the rsync
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
rsync -a source/ destination/
Copy files from source to destination, preserving all attributes (-a = archive mode).
rsync -avz source/ destination/
Copy files in archive mode with verbose output and compression.
rsync -av --delete source/ destination/
Synchronize destination with source, deleting files in destination that don't exist in source.
Advanced Examples:
rsync -avz --progress source/ user@remote-host:/path/to/destination/
Copy files to a remote server with progress indication.
rsync -avz --exclude="*.tmp" source/ destination/
Copy files excluding those matching a pattern (*.tmp files).
rsync -avz --include="*.txt" --exclude="*" source/ destination/
Copy only specific files (only *.txt files in this example).