Rsync Command - File Synchronization Tool | Online Free DevTools by Hexmos

Master rsync commands for efficient file synchronization. Learn to copy, backup, and transfer files with rsync, including advanced options like compression, checksums, and SSH.

Rsync Command Examples

Rsync is a powerful and versatile file-synchronization tool commonly used for backups and mirroring data between systems. It efficiently transfers only the differences between files, making it much faster than traditional copy commands for large datasets or over slow networks. This page provides practical examples of common rsync commands.

Basic File Synchronization

These examples demonstrate fundamental rsync usage for copying files and directories.

# To copy files from remote to local, maintaining file properties and sym-links
# (-a), zipping for faster transfer (-z), verbose (-v):
rsync -avz host:file1 :file1 /dest/
rsync -avz /source host:/dest

Advanced Rsync Options

Explore more advanced options to control how rsync behaves, such as using checksums or preserving directory structures.

# To copy files using checksum (-c) rather than time to detect if the file has
# changed. (Useful for validating backups):
rsync -avc <src> <dest>

# To copy /src/foo folder into destination:
# This command will create /dest/foo if it does not already exist
rsync -auv /src/foo /dest

# To copy contents of /src/foo into destination:
# This command will not create /foo_bak/foo folder
rsync -auv /src/foo/ /foo_bak

Rsync over SSH

Learn how to securely transfer files using rsync over SSH, including specifying ports and authentication keys.

# To copy file from local to remote over ssh with non standard port 1234 to
# destination folder in remoteuser's home directory:
rsync -avz -e "ssh -p1234" <source> <username>@<host>:<dest>

# Use the specified authentication key, instead of typing a password:
# (The key can be generated by ssh-keygen, and the public key should be placed
# in remote's authorized_keys, e.g. using ssh-copy-id)
rsync -avz -e "ssh -i ~/.ssh/id_rsa" <src> <dest>

Discover how to handle privileged files and manage symbolic links with rsync.

# Log into remote as a user, but promote to root, to access privileged files:
rsync -avz --rsync-path="sudo rsync" user@<src> <dest>

# Rsync only symlinks and preserve them as symlinks (dont follow them):
find /path/to/files -type l -print | \
  rsync -av --files-from=- /path/to/files user@targethost:/dest_path

External Resources