7

I'd like to rsync a directory that contains a Python 3 app on my server.

The directory has files I'm interested in: the files that end with .py

And there are the files I'd like to be ignored (these are the files that are inside a __pycache__ directory). (note: there could be __pycache__ directories in any subdirectory of my project). I'd like these __pycache__ directories to be ignored, wherever they appear).

I thought there should be an easy way to do this but couldn't find it. The --filter option appears to be undocumented and the --exclude option doesn't work as described in the rsync help.

3
  • 1
    Look at the --exclude-from option.
    – SunSparc
    Aug 30, 2013 at 16:13
  • I don't know in advance where nor how many the __pycache__ directories are going to be. Aug 30, 2013 at 16:30
  • What have you already tried with --exclude that didn't work?
    – sciurus
    Aug 30, 2013 at 19:43

3 Answers 3

2

rsync -a --exclude "__pycache__/" source/ destination/

You may also want to pass --delete-excluded to remove __pycache__ files that have been copied (of course it removes all other excluded files from the destination too too).

0
rsync -a --exclude '__pycache__' source/ destination/
1
  • 1
    That doesn't work. The __pycache__ directory is still sent. Nov 2, 2015 at 22:07
0

rsync -av --exclude=*__pycache__ source/ destination/

2
  • It yould be nice to have the command explained, especially --exclude so that OP could learn from this, not just see the solution itself (which is IMHO completely correct).
    – bjoster
    Jun 19, 2019 at 8:58
  • 1
    i just posted a fixed syntax (answers above didn't work for me) Jun 19, 2019 at 19:18

Not the answer you're looking for? Browse other questions tagged .