CloudsArk
Commands Linux

What Is the rsync Command in Linux?

Learn what the rsync command does in Linux, how its syntax works, and when to use it.

What Is the rsync Command in Linux?

Introduction

The rsync command synchronizes files locally or over the network. It is useful for beginners, Linux administrators, DevOps engineers, and RHCSA students because it solves practical terminal tasks.

What the Command Does

Use rsync to work with the specific Linux object it manages. Before changing anything, identify the target and run a read-only check when possible.

Basic Syntax

rsync OPTIONS SOURCE DESTINATION

The syntax includes the command, any options, and the target object.

Common Options

  • -a: archive mode.
  • -n: dry run.
  • --delete: remove destination files missing from source.

Practical Examples

rsync -av source/ backup/
rsync -av /srv/app/ /backup/app/
rsync -av --delete source/ backup/
rsync -av -e ssh /srv/app/ admin@server:/backup/app/

Verification command:

rsync -avn source/ backup/

Example output:

sending incremental file list
app.conf
sent 1,024 bytes  received 64 bytes  2,176.00 bytes/sec

When to Use This Command

Use rsync when you need repeatable copies that transfer only differences. It is ideal for backups, deployments, and syncing directories over SSH.

Common Mistakes

  • Misunderstanding the source trailing slash, which changes what gets copied.
  • Using --delete without a dry run.
  • Running as root when preserving ownership is not actually required.

Quick Reference

rsync -av source/ backup/
rsync -av /srv/app/ /backup/app/
rsync -avn source/ backup/

Summary

The rsync command is safest when you understand the target, choose the right option, and verify the result with a separate command.