Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Look at the --exclude-from option. – SunSparc Aug 30 '13 at 16:13
I don't know in advance where nor how many the __pycache__ directories are going to be. – John Smith Optional Aug 30 '13 at 16:30
What have you already tried with --exclude that didn't work? – sciurus Aug 30 '13 at 19:43
rsync -a --exclude '__pycache__' source/ destination/
share|improve this answer
That doesn't work. The __pycache__ directory is still sent. – John Smith Optional Nov 2 '15 at 22:07

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).

share|improve this answer

Your Answer


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.