Specify Includes Only

Steven Monai steve+rsync at monai.ca
Sat Mar 13 21:03:05 MST 2010


On 2010/03/13 3:33 PM, Paul wrote:
> I want to copy only specific directories that contain specific
> filetypes, from sourcedir to destdir. For example, I want to copy all
> .mp3 and all .ogg files found in the GroupA, GroupC directories under
> /home/paul/sourcedir/. For example, if I have
> 
> /home/paul/sourcedir/GroupA/Album1/song.mp3
> /home/paul/sourcedir/GroupA/Album1/cover.jpg
> /home/paul/sourcedir/GroupA/Album2/song.ogg
> /home/paul/sourcedir/GroupA/Album2/cover.jpg
> /home/paul/sourcedir/GroupB/Album1/song.mp3
> /home/paul/sourcedir/GroupC/Album1/song.mp3
> /home/paul/sourcedir/GroupC/Album1/song2.mp3
> 
> then I want to end up with
> 
> /home/paul/destdir/GroupA/Album1/song.mp3
> /home/paul/destdir/GroupA/Album2/song.ogg
> /home/paul/destdir/GroupC/Album1/song.mp3
> /home/paul/destdir/GroupC/Album1/song2.mp3

Try something like this ($ is the command-line prompt):

$ cd /home/paul

$ cat >filt.txt <<EOF
+ */
+ *.mp3
+ *.ogg
- *
EOF

$ cat >dirs.txt <<EOF
sourcedir/GroupA
sourcedir/GroupC
EOF

$ rsync -r --include-from=filt.txt --prune-empty-dirs `cat dirs.txt` destdir

Explanation:

The rules in filt.txt include all directories and all files
that end in .mp3 or .ogg, and exclude everything else. The
--prune-empty-dirs option prevents rsync from creating
empty directories (or more precisely, it causes rsync to
delete any empty directories that it creates).

HTH,
-SM
--


More information about the rsync mailing list