User Tools

Site Tools


tutorials:rsync

Table of Contents

rsync

rsync is a powerful tool for syncing files, either locally on the same machine or remotely between different machines. Use man rsync to read the manual pages to learn more.

Examples

If I want to sync (i.e., update all files that have been newly created or modified and remove all files that have been deleted) the ~/active_project directory on my local workstation up to the server (oak.local in this example), the process can be completed in one command:

rsync -av --delete ~/active_project oak.local:~

Alternatively, if I want to copy only the files that have been changed in /scratch/chkuo/spiro1.02 directory on the server (oak.local again) back to my local workstation, I can use:

rsync -av --delete oak.local:/scratch/chkuo/spiro1.02 /scratch/chkuo

This is better than using scp because rsync can skip files that already exist in the destination and have not been updated in the source.

It is important to note that the absence or presence of the trailing slash at the end of the source directory (i.e., ~/active_project versus ~/active_project/) have different effects, so be careful.

Advanced uses

If we need to sync some directories quite often (like the ~/active_project example above), it is easier to save the command in a schell script and place the script somewhere in the search path (~/bin or ~/script for example, see .bashrc for more info).

tutorials/rsync.txt · Last modified: 2012/06/15 01:18 by chkuo