Linuxlab

File sync in Linux: the rsync command

Updated July 3, 2026

rsync copies and syncs directories, sending only what has changed.

Syntax

rsync [options] source destination

Common cases

rsync -a src/ dst/                  # sync locally
rsync -av src/ dst/                 # -v show what is copied
rsync -a src/ alice@server:/backup/ # to a remote server over ssh
rsync -an --delete src/ dst/        # -n dry run: what would change
rsync -a --delete src/ dst/         # make dst an exact copy of src

How it works: only the difference, and the trailing slash

rsync first compares the source and destination and sends only the changed parts of files - so syncing a large directory again is fast. The -a (archive) flag keeps permissions, times and structure. One important subtlety is the trailing slash on the source: src/ copies the directory's contents, while src (no slash) copies the directory itself into the destination. --delete removes things in the destination that are gone from the source - powerful and dangerous, so run it with -n first (a dry run that changes nothing).

In the book

This topic is covered in full in the chapter Archives and backups.

See also

SSH and scp, tar archives, Backup and restore.