Let's say that I want to sync a folder with unison, but I want to sync only .jpg files.
How I could do that?
You need to add the following lines to your profile:
ignore = Name ?*
ignorenot = Name *.jpg
Eight years later ... the accepted doesn't properly ignore files with no period, or dotfiles.
And any pattern (say, Regex ^((?!.jpg).)*$
) that does matche these will also gobble directories that might have .jpg as a child. (See "Unison starts detecting updates..." under Ignoring Paths in the manual.)
The only way I've found is to let the sync proceed with those extra files included, and then use
find "$DEST" --type f ! -iname "*.jpg" -delete
find "$DEST" --type d -empty -delete
to kill them, and then clean up the empty directories. (In my case, I actually did
find "$DEST" --type d -empty ! -name ".stfolder" -delete
to preserve a SyncThing marker directory--don't ask.)
A potentially bad consequence of this is copying lots of extra data for a short time--in my case, some 3.5GB moves from one partition to another, and then is promptly deleted.