Rsync Command: 20 Helpful Examples in Linux

The rsync command in Linux provides an efficient way to synchronize and transfer files between local and remote systems. This powerful tool enables copying and updating files while preserving permissions and timestamps, excluding specific files or directories, and compressing data during transfer. It supports incremental synchronization, backup operations, and bandwidth limitations while ensuring data integrity through checksums.

20 Helpful Rsync Examples

These examples demonstrate the versatility and functionality of rsync, from basic local file copying to advanced remote transfers over SSH. Each example includes practical usage scenarios that showcase rsync's capabilities for file synchronization and backup tasks.

Example 1: Copying Files Locally

Use rsync to copy files within the same system ?

rsync source_directory/ destination_directory/

Example 2: Synchronizing Directories

Synchronize the contents of two directories, copying only modified files ?

rsync -av source_directory/ destination_directory/

Example 3: Preserving Permissions and Timestamps

Ensure file permissions and timestamps are preserved during synchronization ?

rsync -av --preserve-permissions --times source_directory/ destination_directory/

Example 4: Excluding Specific Files or Directories

Exclude certain files or directories from the synchronization process ?

rsync -av --exclude='file.txt' --exclude='directory/' source_directory/ destination_directory/

Example 5: Deleting Extra Files at Destination

Delete files at the destination that don't exist in the source directory ?

rsync -av --delete source_directory/ destination_directory/

Example 6: Transferring Files Over SSH

Synchronize files between local and remote systems securely using SSH ?

rsync -avz -e ssh source_directory/ user@remote_host:/destination_directory/

Example 7: Bandwidth Limitation

Limit the bandwidth used during the synchronization process (in KB/s) ?

rsync -avz --bwlimit=1000 source_directory/ destination_directory/

Example 8: Verbose Output with Progress

Display detailed information about the synchronization process ?

rsync -av --progress source_directory/ destination_directory/

Example 9: Dry Run (Preview Mode)

Simulate the synchronization process without actually copying files ?

rsync -av --dry-run source_directory/ destination_directory/

Example 10: Exclude File Extensions

Exclude files with specific extensions from synchronization ?

rsync -av --exclude='*.txt' source_directory/ destination_directory/

Example 11: Resume Interrupted Transfers

Resume interrupted file transfers from the last point of interruption ?

rsync -av --partial source_directory/ destination_directory/

Example 12: File Transfer with Compression

Compress files during transfer to reduce bandwidth usage ?

rsync -avz source_directory/ destination_directory/

Example 13: Creating Incremental Backups

Create incremental backups using hard links to save space ?

rsync -av --link-dest=/backup/previous_backup/ source_directory/ /backup/current_backup/

Example 14: Verifying File Integrity

Use checksums to verify file integrity during synchronization ?

rsync -av --checksum source_directory/ destination_directory/

Example 15: Archive Mode Transfer

Transfer files in archive mode, preserving symbolic links, permissions, and more ?

rsync -a source_directory/ destination_directory/

Example 16: Compression with Progress Bar

Display a progress bar while transferring files with compression ?

rsync -avz --progress source_directory/ destination_directory/

Example 17: Limiting File Size

Exclude files larger than a specific size from synchronization ?

rsync -av --max-size=10M source_directory/ destination_directory/

Example 18: SSH Key Authentication

Authenticate with remote systems using SSH keys instead of passwords ?

rsync -avz -e "ssh -i /path/to/private_key" source_directory/ user@remote_host:/destination_directory/

Example 19: Excluding Hidden Files

Exclude hidden files and directories from synchronization ?

rsync -av --exclude='.*' source_directory/ destination_directory/

Example 20: Detailed Change Analysis

Demonstrate synchronization with detailed change information ?

rsync -av --dry-run --itemize-changes source_directory/ destination_directory/

Common Rsync Options

Option Description
-a, --archive Archive mode; preserves permissions, timestamps, symbolic links
-v, --verbose Increase verbosity for detailed output
-z, --compress Compress file data during transfer
--delete Delete extraneous files from destination
--exclude Exclude files matching specified pattern
--dry-run Perform trial run without making changes

Conclusion

Rsync is an essential tool for file synchronization and backup tasks in Linux, offering powerful features like incremental transfers, compression, and remote synchronization over SSH. These 20 examples demonstrate its versatility in handling various scenarios from simple local copying to complex remote backup operations with bandwidth control and integrity verification.

Updated on: 2026-03-17T09:01:39+05:30

405 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements