Top 10 Features of Rsync:
- Efficient File Transfer:
- Rsync only transfers the differences between source and destination files, minimizing data transfer and speeding up synchronization.
- Delta Transfer Algorithm:
- Rsync uses a delta algorithm to detect and transfer only the changed parts of files, reducing bandwidth usage significantly.
- Support for Local and Remote Sync:
- Rsync can synchronize files locally (between directories on the same system) or remotely (between different systems over SSH or direct connections).
- Preservation of File Attributes:
- Rsync can preserve file permissions, ownerships, timestamps, symbolic links, and other metadata, ensuring data integrity during transfers.
- Compression:
- It supports data compression during transfers, reducing bandwidth requirements and speeding up file synchronization.
- Resume Interrupted Transfers:
- Rsync can resume interrupted transfers without restarting from scratch, making it ideal for large file synchronizations.
- Exclude/Include Patterns:
- It allows you to include or exclude specific files or directories from synchronization using flexible pattern matching rules.
- Backup Support:
- Rsync can create backups by appending timestamps to files or directories, enabling incremental backups with minimal storage overhead.
- SSH Integration:
- Rsync seamlessly integrates with SSH for secure file transfers, ensuring data is encrypted during remote synchronizations.
- Cross-Platform Compatibility:
- Rsync works on various platforms, including Linux, macOS, and Windows (using tools like Cygwin or WSL), making it a versatile tool for synchronization tasks.
These features make Rsync an invaluable utility for efficient and reliable file synchronization, backup, and data replication tasks.
Here are the top 50 most commonly used rsync
commands and options, categorized for better understanding:
Basic Commands
rsync source/ destination/
- Basic directory synchronization.
rsync file1 destination/
- Transfer a single file to the destination.
rsync -r source/ destination/
- Recursively copy directories.
rsync -a source/ destination/
- Archive mode for preserving metadata.
rsync -v source/ destination/
- Enable verbose output.
Common Options
rsync -z source/ destination/
- Compress file data during transfer.
rsync -P source/ destination/
- Show progress and allow resuming of partial transfers.
rsync -h source/ destination/
- Human-readable file sizes.
rsync -q source/ destination/
- Suppress non-error messages.
rsync -i source/ destination/
- Output changes made during synchronization.
Advanced File Attributes
rsync -t source/ destination/
- Preserve modification times.
rsync -o source/ destination/
- Preserve ownership.
rsync -g source/ destination/
- Preserve group ownership.
rsync -p source/ destination/
- Preserve permissions.
rsync -l source/ destination/
- Copy symbolic links as is.
rsync -H source/ destination/
- Preserve hard links.
rsync -D source/ destination/
- Preserve device and special files.
Deletion Options
rsync --delete source/ destination/
- Delete files in the destination not present in the source.
rsync --delete-before source/ destination/
- Delete files in the destination before transferring new files.
rsync --delete-during source/ destination/
- Delete files in the destination during the transfer process.
rsync --delete-delay source/ destination/
- Delete files in the destination after the transfer is complete.
SSH Integration
rsync -e ssh source/ user@remote:/destination/
- Use SSH for secure remote transfers.
rsync -e "ssh -p 2222" source/ user@remote:/destination/
- Use a custom SSH port.
rsync -e "ssh -i /path/to/key" source/ user@remote:/destination/
- Use an SSH key for authentication.
Include/Exclude Files
rsync --exclude='*.tmp' source/ destination/
- Exclude files matching a pattern.
rsync --include='*.jpg' source/ destination/
- Include files matching a pattern.
rsync --exclude-from=exclude-list.txt source/ destination/
- Exclude files listed in a file.
rsync --include-from=include-list.txt source/ destination/
- Include files listed in a file.
Backup and Restore
rsync --backup source/ destination/
- Create backups of existing files.
rsync --backup-dir=/path/to/backup source/ destination/
- Specify a backup directory.
rsync --suffix=.backup source/ destination/
- Append a suffix to backup files.
Progress and Logging
rsync --progress source/ destination/
- Show progress during transfer.
rsync --log-file=rsync.log source/ destination/
- Save logs to a file.
Checksum and Integrity
rsync -c source/ destination/
- Use checksum to determine file differences.
rsync --checksum
- Always verify file integrity with checksums.
Bandwidth and Performance
rsync --bwlimit=1000 source/ destination/
- Limit bandwidth to 1000 KB/s.
rsync --whole-file source/ destination/
- Transfer the whole file instead of using deltas.
Dry Run
rsync --dry-run source/ destination/
- Simulate synchronization without making changes.
Hard Links and Symlinks
rsync -L source/ destination/
- Copy symlinks as the files they point to.
rsync --copy-links source/ destination/
- Same as
-L
.
Partial Transfers
rsync --partial source/ destination/
- Keep partially transferred files to resume later.
rsync --partial-dir=.rsync-partial source/ destination/
- Store partial files in a specific directory.
Parallel Transfers
rsync --compress-level=9 source/ destination/
- Set compression level to maximum.
File Size Control
rsync --max-size=10MB source/ destination/
- Exclude files larger than 10MB.
rsync --min-size=100KB source/ destination/
- Exclude files smaller than 100KB.
Archiving
rsync -a --delete source/ destination/
- Archive and remove extraneous files.
rsync -a --progress source/ destination/
- Archive mode with progress output.
Version Information
rsync --version
- Check the version of
rsync
.
Remote-to-Remote Sync
rsync -a user@remote1:/path/ user@remote2:/path/
- Synchronize between two remote systems.
Exclude Hidden Files
rsync --exclude='.*' source/ destination/
- Exclude hidden files (starting with a dot).
These commands cover most use cases for file synchronization, backup, and replication using rsync
.