سؤال

Right now I'm successfully running:

rsync -uvma  --include="*/" --include="*.css" --exclude="*" $spec_dir $css_spec_dir

In a shell script which copies all of the files in the source directory, that are .css files, into a target directory.

I want to do the same for HTML files, but only where they are in a subfolder with the name 'template'.

So I'm in directory ~/foo, and I want to rsync where the --include="*/" only matches on subfolders with the name 'template'. So ~/foo/bar/template/baz/somefile.html would match, and so would ~foo/bar/baz/qux/template/someotherfile.html, but NOT ~/foo/bar/thirdfile.html

هل كانت مفيدة؟

المحلول 3

Here's what worked:

rsync -uvma --include="*/" --include="templates/**.html"  --exclude="*" $html_all_dir $html_dir

My guess is, your format and mine probably accomplish the same thing. I know I tried about 20 different patterns before this one, and this is the only one that worked properly. I don't think I tried your format though :)

نصائح أخرى

Although it looks a little bit strange, this works for me:

rsync -uvma --include="*/" --include="*/template/*/*.html" --include="*/template/*.html" --include="template/*.html" --include="template/*/*.html" --exclude="*" $spec_dir $html_spec_dir

This one works for me:

rsync -umva --include="**/templates/**/*.html" --exclude="*.html" source/ target

Were you looking for **? Here you have to be careful about choosing your exclude pattern, * won't work as it matches directories on the way. If rsync finds foo/templates/some.html, it will first copy foo, then foo/templates and then foo/templates/some.html, but before it gets there * already matched foo and nothing gets copied.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top