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 destinationCommon 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 srcHow it works: only the difference, and the trailing slash
rsyncfirst 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, whilesrc(no slash) copies the directory itself into the destination.--deleteremoves things in the destination that are gone from the source - powerful and dangerous, so run it with-nfirst (a dry run that changes nothing).
In the book
This topic is covered in full in the chapter Archives and backups.