• 0
Back to: Geek Stuff
Monday, 14. december 2009.

Synchronize two folders on a Mac and other Unix Systems with Rsync

From terminal

One of the great things with Mac OS X is that you have many of the cool tools from UNIX world. One of them is definitely Rsync. I'll show you how to use it to synchronise files from of two different folders from terminal and using mighty automator.

Here is the simple example of syncing two folders from terminal:

rsync -va --delete ~/Folder1/ ~/Folder2/

What this line does is comparing contents of Folder1 with what you have in Folder2 and copies all new and newer files and folders from Folder1 to Folder2.

This "--delete" option tells it that you want also to delete files and folders from Folder2 that do not exist in Folder1. So in case that you'd like to leave those files/folders in Folder2, you just omit this part.

Option "-va" hides two options actually, "v" stands for Verbose, so it will inform you what's being done.

And "a" stands for archive mode, which means that the operation will be recursive so it looks inside of all subfolders you have in Folder1 and Folder2, and that it will keep the permissions intact and also some other things.

You can always check the manual of Rsync by typing "man rsync" in terminal.

In case you don't want to sync some particular files or folders you can specify it with "--exclude" option. So for example if you don't want to sync file named "leave_me_alone.txt" you just add this "--exclude='leave_me_alone.txt'", so your whole command would look like:

rsync -va --exclude='leave_me_alone.txt' --delete ~/Folder1/ ~/Folder2/

And you can add more files by just adding another "--exclude":

rsync -va --exclude='leave_me_alone.txt' --exclude='not_going_anywhere.doc' --delete ~/Folder1/ ~/Folder2/

But the real power comes from the fact that you can use patterns, so if you have a lot of let's say Microsoft Word files that you'd like to ignore for some reason, you can do this:

rsync -va --exclude='*.doc' --delete ~/Folder1/ ~/Folder2/

And now you can go on and see how can you use all this stuff in Automator and make it work without terminal...

Thanks a lot! I was looking for --delete example :)

eMancu
23. Feb 2010 at 4:35 AM

Comment

Calendar

January 2010

  • mon
  • tue
  • wed
  • thu
  • fri
  • sat
  • sun
  •  
  •  
  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

December 2009

  • mon
  • tue
  • wed
  • thu
  • fri
  • sat
  • sun
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

May 2009

  • mon
  • tue
  • wed
  • thu
  • fri
  • sat
  • sun
  •  
  •  
  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31