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...
Recent posts
- Tuesday, 11. may 2010. First look at Navicat 9 for MySQL, Mac OS X version
- Thursday, 21. january 2010. Find files larger than X and delete them in Mac OS/Unix terminal
- Tuesday, 15. december 2009. Bananica.com - Finally!
- Monday, 14. december 2009. MySQL Find and Replace with helper tool that generates SQL for you
- Monday, 14. december 2009. Synchronize two folders on a Mac with Automator and Rsync
- Monday, 14. december 2009. Synchronize two folders on a Mac and other Unix Systems with Rsync
Recent comments
-
Wednesday, 28. juli 2010. ludo commented on Bob Dylan Live Sucks Typial comments from the types of drunk stoned idiots who when at Dylan gigs scream
and whistle shout their own selfish prefrences deafening other audience members and unsettling Bob. Why dont you just keep it quiet? - Sunday, 27. june 2010. Jamie commented on Synchronize two folders on a Mac and other Unix Systems with Rsync Be aware that the version of rsync that comes with OS X (10.6) ignores resource forks and other metadata unless you supply -E or --extended-attributes. That’s not perfect either and I tried to post further details but this site wouldn’t allow me.
-
Thursday, 22. april 2010. Crocodil commented on Synchronize two folders on a Mac with Automator and Rsync Marvelous !
I was searching such tutorial a long time ago, thanks so much :-)
Thanks a lot! I was looking for --delete example :)
23. Feb 2010 at 4:35 AM
Be aware that the version of rsync that comes with OS X (10.6) ignores resource forks and other metadata unless you supply -E or --extended-attributes. That’s not perfect either and I tried to post further details but this site wouldn’t allow me.
27. Jun 2010 at 1:11 AM