Linux: Sync Across Machines, rsync

By Xah Lee. Date: . Last updated: .

rsync is a command line util that lets you do one-way copying/updating from one machine to another.

The remote machine must also have rsync installed. (it's installed by default in linux)

rsync -z -a -v -t --rsh="ssh -l joe" ~/web/ joe@example.org:~/

This will copy the local dir ~/web/ to the remote dir ~/ on the machine with domain name “example.org”, using login “joe” via the ssh protocol.

Here's what the options mean:

For example, here's what i use to sync/upload my website on my local machine to my server.

rsync -z -a -v -t --exclude="*~"  --exclude=".DS_Store" --exclude=".bash_history"  --exclude="*/_curves_robert_yates/*.png" --exclude="logs/*"  --exclude="xlogs/*" --delete --rsh="ssh -l joe" ~/web/ joe@example.com:~/

Here's a example of syncing Windows and Mac.

rsync -z -r -v --delete --rsh="ssh -l xah" ~/web/ xah@169.254.125.147:~/web/

Note that -r is used instead of -a. The -r means recursive, all sub directories and files. Don't use -a because that will sync file owner, group, permissions, and others, but because Windows and unix have different permission systems and file systems, so -a is usually not what you want.

[see Linux: File Permission System]

Reverse Direction

Here's a example of reverse direction.

rsync -z -a -v -t --rsh="ssh -l joe" joe@example.org:~/web/ ~/

This will get everything from the remote machine, to local machine.

Two-way Synchronize with Unison

How to Use Unison for Syncing Files (Unison tutorial)

Downloading a Entire Website

Linux: Download Website: wget, curl, HEAD, GET

Compare Directories

[see Linux: Compare Files or Directory: diff]

Shell Basics

  1. Get System Info
  2. Shell Basics
  3. grep, cat, awk, uniq
  4. sort
  5. find, xargs
  6. diff Files/Dir
  7. dir size: du
  8. dir tree
  9. tar gzip bzip2 xz 7zip rar zip
  10. wget, curl, GET, HEAD
  11. rsync
  12. Install Packages

If you have a question, put $5 at patreon and message me.