Prabhakar Shanmugam
Prabhakar Shanmugam

Reputation: 6144

Using rsync to sync only files that are modified

I am trying to sync two folders

/developer and /shared ( in ubuntu )

when I modify a file in /shared , I would like to be able to copy the file to the /developer folder

I tried

rsync -r /shared /developer

But it seems to copy everything, although I changed only two files there.

How to copy only the changed files.

I also tried

rsync -rtu /shared /developer

somehow I can't get my head around this.

Please help.

Upvotes: 8

Views: 19579

Answers (2)

Amalya
Amalya

Reputation: 1

Well , this also works

rsync -au --delete --update /shared/ /developer/

Upvotes: -1

ams
ams

Reputation: 25559

Try this:

rsync -a /shared/ /developer/

The first time you run that it will update the access times etc. for every file, but subsequent runs will only copy what's updated.

  • -a means "archive". It implies -r, but also -t which is what you're missing.
  • The trailing slashes on the directory names are important. With no slash it'll copy the source directory into the destination directory, like cp does. This means it behaves differently when the destination already does or does not exist.

Edit: if you expect it to remove files that no longer exist in /shared then add --delete, and use it carefully.

Upvotes: 13

Related Questions