Skip to content

rsync command

Sync files and directories locally or over SSH, copying only what changed.

On this page

Syntax

rsync [options] source destination

Provided by the rsync package. Run man rsync for the full manual.

Common options

OptionWhat it does
-aArchive: recursive, keep permissions, times, links
-vVerbose
-zCompress during transfer
-PShow progress and keep partial files
-nDry run: show what would happen
--deleteDelete files in the destination that are gone from the source
--exclude=PATTERNSkip matching files
-e "ssh -p N"Use SSH on another port

Examples

  1. Copy a directory locally

    rsync -a /var/www/ /backup/www/
  2. Copy to a server

    rsync -avz site/ user@server:/var/www/site/
  3. Download from a server

    rsync -avz user@server:/var/backups/ ./backups/
  4. Mirror exactly (deletes extras)

    rsync -a --delete src/ dest/
  5. Preview first

    rsync -avn --delete src/ dest/
  6. Show progress, resume big files

    rsync -aP bigfile.iso user@server:~
  7. Exclude files

    rsync -av --exclude="node_modules" --exclude="*.log" app/ backup/
  8. Use another SSH port

    rsync -av -e "ssh -p 2222" data/ user@server:/data/
  9. Only copy files missing at the destination

    rsync -av --ignore-existing src/ dest/

Tips

  • A trailing slash matters: src/ copies the contents, src copies the directory itself.

rsync guides

← All Linux commands · Suggest a fix

Back to top