thefekete.net

$> :(){ :|:& };:

RSync include only certain file types, or exclude all but…

I was recently working on something for my company and needed to transfer all of our product pictures to my home computer. Unfortunately, all the actual product PNGs are intermingled with their corresponding and huge XCFs and other working files. Thus, I needed to exclude all files except the PNGs. Or, to include only the PNGs.

Here’s how to do it:

#!/bin/bash

rsync --include='*/' --include='*.png' --exclude='*' \
--prune-empty-dirs \
example.com:/path/to/source ./

Thanks to Dude for the tip on pruning empty directories. See his Comment below.

I pulled this from here.

7 Responses to “RSync include only certain file types, or exclude all but…”

  1. bethany says:

    Awesome. Hope everyone searching “rsync exclude everything except” finds this!

  2. ajos1 says:

    –prune-empty-dirs

    should read

    -–prune-empty-dirs

    otherwise it gets interpretted at a DRY RUN! -n

  3. Ajos1 says:

    Most excellent news… speeded up my rpm/dprm synchronisation zillions of percent…

  4. Dude says:

    use –prune-empty-dirs (-m) or it will create empty directorys of what you didn’t include

  5. Søren Holm says:

    Sweet – just what I needed.

Leave a Reply

HTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting