Linux command
rsync 命令
网络
需要网络或远程资源。
常用示例
Sync a local directory to another location
rsync -av [source/] [destination/]
Sync to a remote server via SSH
rsync -av [source/] [user]@[host]:[destination/]
Sync from a remote server
rsync -av [user]@[host]:[source/] [destination/]
Delete files in destination
rsync -av --delete [source/] [destination/]
Dry run
rsync -avn [source/] [destination/]
Show progress
rsync -av --progress [source/] [destination/]
Exclude files matching a pattern
rsync -av --exclude="*.log" [source/] [destination/]
Compress during transfer
rsync -avz [source/] [user]@[host]:[destination/]
说明
rsync is a fast, versatile file copying tool that synchronizes files between locations. It uses a delta-transfer algorithm, transmitting only differences between source and destination, making it efficient for incremental backups and mirrors. The trailing slash on source paths is significant: source/ copies contents, while source copies the directory itself. This is a common source of confusion. Rsync can operate locally or over a network using SSH (default), RSH, or its own daemon protocol. For remote transfers, format is user@host:path or rsync://user@host/path for daemon mode. The -a (archive) flag is commonly used as it preserves permissions, timestamps, symbolic links, and recurses into directories—suitable for most backup scenarios.
参数
- -a, --archive
- Archive mode; equals -rlptgoD (recursive, links, perms, times, group, owner, devices)
- -v, --verbose
- Increase verbosity
- -z, --compress
- Compress file data during transfer
- -n, --dry-run
- Show what would be transferred without making changes
- --delete
- Delete files in destination that don't exist in source
- --exclude=_pattern_
- Exclude files matching pattern
- --include=_pattern_
- Include files matching pattern (after excludes)
- --progress
- Show progress during transfer
- -P
- Same as --partial --progress
- --partial
- Keep partially transferred files
- -r, --recursive
- Recurse into directories
- -u, --update
- Skip files newer on destination
- -c, --checksum
- Compare by checksum, not mod-time & size
- -e _command_
- Specify remote shell to use (e.g., -e ssh)
- --bwlimit=_KBPS_
- Limit bandwidth in KB/s
- -h, --human-readable
- Output numbers in human-readable format
FAQ
What is the rsync command used for?
rsync is a fast, versatile file copying tool that synchronizes files between locations. It uses a delta-transfer algorithm, transmitting only differences between source and destination, making it efficient for incremental backups and mirrors. The trailing slash on source paths is significant: source/ copies contents, while source copies the directory itself. This is a common source of confusion. Rsync can operate locally or over a network using SSH (default), RSH, or its own daemon protocol. For remote transfers, format is user@host:path or rsync://user@host/path for daemon mode. The -a (archive) flag is commonly used as it preserves permissions, timestamps, symbolic links, and recurses into directories—suitable for most backup scenarios.
How do I run a basic rsync example?
Run `rsync -av [source/] [destination/]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -a, --archive do in rsync?
Archive mode; equals -rlptgoD (recursive, links, perms, times, group, owner, devices)