Rsync is a powerful and versatile file synchronization tool for efficiently copying and transferring files between local and remote hosts. This cheat sheet provides essential Rsync commands for various use cases.

Introduction:

Rsync is known for its ability to efficiently synchronize files and directories across different systems while minimizing data transfer. It uses the SSH protocol for secure remote transfers and supports a wide range of options for fine-tuned control.

Basic File Synchronization:

CommandDescription
rsync [source] [destination]Synchronize files and directories locally.
rsync -av [source] [destination]Archive mode: Preserves permissions and other attributes.

Synchronize with a Remote Server (Using SSH):

CommandDescription
rsync -av -e ssh [source] [username]@[hostname]:[destination]Synchronize with a remote server using SSH.
rsync -av --delete -e ssh [source] [username]@[hostname]:[destination]Delete extraneous files on the destination.

Include and Exclude Files:

CommandDescription
rsync -av --include=[pattern] --exclude=[pattern] [source] [destination]Include and exclude specific files based on patterns.
rsync -av --exclude-from=[file] [source] [destination]Exclude files listed in a file.

Advanced Options:

CommandDescription
rsync -av --progress [source] [destination]Display transfer progress.
rsync -av --bwlimit=[limit] [source] [destination]Limit bandwidth usage during transfer.
rsync -av --dry-run [source] [destination]Perform a dry run without making any changes.

Using Rsync Daemon:

CommandDescription
rsync -av [source] rsync://[username]@[hostname]/[module]Connect to an Rsync daemon on a remote server.

Backup with Rsync:

CommandDescription
rsync -av --link-dest=[backup_dir] [source] [backup_destination]Create incremental backups using hard links.
rsync -av --delete --backup --backup-dir=[backup_dir] [source] [destination]Perform backups with versioning.

Using Rsync for Bandwidth-Efficient Transfers:

CommandDescription
rsync -avz [source] [username]@[hostname]:[destination]Enable compression for data transfer.
rsync -av --partial --progress [source] [destination]Partially transfer files for resumable transfers.

Conclusion

Rsync is a versatile and efficient tool for file synchronization, whether you are working locally or remotely. This cheat sheet provides a quick reference for commonly used Rsync commands, covering basic file synchronization, remote transfers, include/exclude options, and advanced features like backup and bandwidth-efficient transfers. Whether you are a system administrator or a developer, mastering these commands will enhance your ability to manage and synchronize files across different systems.