How to rsync only specified subdirectories in the source folder?

Wesley W. Terpstra wesley at
Wed Nov 1 13:14:17 GMT 2006

On Nov 1, 2006, at 6:00 AM, woo robbin wrote:
> For example,if there is ten subdirectories named sub1~sub10(each  
> including subdirectories and files too),and file1~file10,how can I  
> rsync only sub2 and sub 3 to the target?
> rsync -av --delete --include "/sub2/" --include "/sub3/" / 
> MyFolder/   /dest/
> this seems to sync other directories and files too.

The reason that doesn't work is because include only cancels out an  
exclude. Since you've not excluded anything, the include does  
nothing. You could add an --exclude '/*' if you wanted to do this  
with include/excludes:
	rsync -av --delete --include "/sub2/" --include "/sub3/"--exclude '/ 
*' /MyFolder/   /dest/

	rsync -av --delete /MyFolder/sub2 /MyFolder/sub3 /dest
is probably the simplest (and therefore best) solution.

More information about the rsync mailing list