selectively copying files

Benjamin R. Haskell rsync at benizi.com
Thu Jan 13 08:02:10 MST 2011


On Thu, 13 Jan 2011, Mag Gam wrote:

> bump
>
> On Tue, Jan 11, 2011 at 8:52 PM, Mag Gam wrote:
>> Hello All,
>>
>> I am trying to sync 2 directories.
>>
>> src/year/month/day/fileA.csv
>> src/year/month/day/fileB.csv
>> src/year/month/day/fileC.csv
>> ..
>> src/year/month/day/fileZ.csv
>>
>> I would to sync only file{B,D,T}.csv to my target directory so it 
>> would look like this.
>>
>> tgt/year/month/day/fileB.csv
>> tgt/year/month/day/fileD.csv
>> tgt/year/month/day/fileT.csv
>>
>> what is the best way to do this?
>>

rsync -av --prune-empty-dirs --include='*/' --include='file[BDT].csv' --exclude='*' src/ tgt/

First --include makes sure all directories are considered
Second (and further) --includes should match your file patterns.
The --exclude excludes everything else.

Without the first --include='*/', every directory would be excluded by 
--exclude='*', so no directory recursion would take place.

--prune-empty-dirs excludes any directories with no file matches.  (Not 
obvious from your example whether that's useful/necessary.)

-- 
Best,
Ben


More information about the rsync mailing list