Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Say I have the following structure on path origin_path

origin_path/X=1/A/...
origin_path/X=1/B/...
origin_path/X=1/C/...
...
origin_path/X=2/A/...
origin_path/X=2/B/...
origin_path/X=2/C/...
...
...

I would like to replicate the structure above at a different path called destination_path, but only including the paths corresponding to the directories B above.

In other words, I would like to get the following at destination_path

destination_path/X=1/B/...
destination_path/X=2/B/...
destination_path/X=3/B/...
...

To clarify, some of this structure in destionation path might exist already (e.g. the folders destination_path/X=*).

From what I understand, thanks to @Gilles' comment, rsync filters may be a great fit for this. However, I have never used them before and it's a bit hard for me to extrapolate the example provided in Rsync filter: copying one pattern only to my situation.

In what order should I include or exclude things in my case? And how do I tell rsync to use origin_path and destination_path as global paths? (as opposed to having it copy things with relative paths)

share|improve this question
    
Is Rsync filter: copying one pattern only the same problem? If not, please update your question to explain the difference (I'm not sure exactly what your selection criteria are). –  Gilles Mar 22 '12 at 23:58
    
Thanks @Guilles. From what I understand, I think rsync filters are a great fit for this. I went through your answer and read about them a bit more online, but I am not sure how what would be the right rule here. I'll clarify my question too. –  user815423426 Mar 23 '12 at 13:51
    
I have updated my answer @Gilles. I hope what I am asking for is much clearer now. –  user815423426 Mar 23 '12 at 14:00
add comment

1 Answer 1

The following should do what you want:

rsync --recursive --prune-empty-dirs --include '*/' --include '*/B/**' --exclude '**' origin_path/ destination_path/

The first rule includes all directories (otherwise rsync won't descend into the top level directories). The second rule includes everything in a "B" subdirectories. The third rule excludes everything else. The --prune-empty-dirs option ignores empty directories (since we're including all directories with the first rule).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.