Efficiently copy and synchronize files and directories locally or over the network.
rsync copies files and directories while transferring only the differences when possible. It is widely used for backups, mirroring, migrations, and keeping directories in sync.
# Copy one directory to another rsync -av source/ destination/ # Copy to remote machine over SSH rsync -av /home/user/ user@server:/backup/user/ # Dry run first rsync -av --dry-run source/ destination/
-a Archive mode (preserve most metadata; recurse) -v Verbose -h Human-readable numbers -z Compress during transfer --progress Show transfer progress --dry-run Show what would happen, but do nothing --delete Delete files on destination not present in source --exclude=PAT Skip matching files --include=PAT Include matching files -e ssh Use SSH as remote shell -n Short form of --dry-run -r Recurse into directories -u Skip files newer on receiver -P Equivalent to --partial --progress
rsync -av source/ dest/ # copies CONTENTS of source into dest rsync -av source dest/ # copies the source DIRECTORY itself into dest
This is one of the most important things to understand in rsync.
# 1) Sync one local directory to another rsync -av /home/craig/docs/ /mnt/backup/docs/
# 2) Dry run before syncing rsync -av --dry-run /home/craig/docs/ /mnt/backup/docs/
# 3) Show progress during copy rsync -avh --progress /home/craig/videos/ /mnt/backup/videos/
# 4) Sync to remote server over SSH rsync -av /home/craig/docs/ craig@server:/backup/docs/
# 5) Sync from remote server to local machine rsync -av craig@server:/backup/docs/ /home/craig/restore/docs/
# 6) Compress during network transfer rsync -avz /home/craig/data/ craig@server:/backup/data/
# 7) Delete files on destination that no longer exist in source rsync -av --delete /home/craig/docs/ /mnt/backup/docs/
# 8) Exclude log files rsync -av --exclude="*.log" /var/www/ /backup/www/
# 9) Exclude cache directories rsync -av --exclude="cache/" /home/craig/project/ /backup/project/
# 10) Resume large interrupted transfer rsync -avP bigfile.iso /mnt/backup/
# 11) Use a different SSH port rsync -av -e "ssh -p 2222" /home/craig/docs/ craig@server:/backup/docs/
# 12) Sync only files newer in source rsync -avu /home/craig/docs/ /mnt/backup/docs/
# Mirror a website directory rsync -av --delete /var/www/html/ /backup/www/html/
# Backup home directory but skip caches and trash rsync -av \ --exclude=".cache/" \ --exclude=".local/share/Trash/" \ /home/craig/ /mnt/backup/home-craig/
# Safer first step: dry run with delete rsync -av --delete --dry-run /source/ /dest/
# Copy photos to external drive with progress rsync -avhP ~/Pictures/ /run/media/craig/PHOTO_BACKUP/Pictures/
--delete is powerful and can remove a lot. Use --dry-run first.-a is usually the right starting point for directory syncs.-z helps over slower networks, but may not help much for already-compressed files.-u can be useful, but make sure its behavior matches what you want.rsync is a sync/copy tool, not a versioned backup system by itself.# SAFEST workflow: # 1) dry run first rsync -av --dry-run /source/ /dest/ # 2) if delete is involved, dry run that too rsync -av --delete --dry-run /source/ /dest/ # 3) then do the real run rsync -av /source/ /dest/
With rsync, previewing first is one of the best habits you can have.
rsync became popular because it could efficiently synchronize files by transferring only differences instead of copying everything every time. That made it especially valuable for backups and network transfers.
Modern backup tools like restic, borg, and snapshot-based systems can do more, especially for versioned backups. But rsync remains one of the most trusted and flexible tools for straightforward sync and copy tasks.