It is inconceivable that this is proving to be so difficult but I'm trying to use rsync to copy only files matching a specific pattern. Specifically, copy files in all subdirectories matching "*000.csv"

You would think that the following

rsync -avrP --include='*000.csv' host:'~/data/' .

would do the trick. Instead this targets all files in all subdirectories (?!). This blog suggests you can only "include" things that have been excluded first. Okay, so then why do these:

rsync -avrP --exclude='*' --include='*000.csv' host:'~/data/' .

rsync -avrP --filter='-! */' --include='*000.csv' host:'~/data/' .

both target no files at all. Please help. Thank you.

marked as duplicate by roaima, cas, Archemar, Jeff Schaller, telcoM Feb 3 '18 at 14:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • try **/*000.csv or **000.csv. * matches anything except slashes, ** matches anything including slashes. see man rsync and search for "PATTERN RULES". – cas Feb 3 '18 at 2:47

From your code, it looks like you are trying to copy from the remote host to your local machine. With that being said:

rsync -avP --include=*000.csv --exclude=*.* user@host:~/data ./

You don't need r as a implies r.

  • Thatll only get the files matching the pattern in the top level directory – Jon Deaton Feb 3 '18 at 2:46
  • Just tried it. It actually matches all files, even those that don't match *000.csv for some reason :( – Jon Deaton Feb 3 '18 at 4:38
  • The first command has been edited. – Nasir Riley Feb 3 '18 at 16:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.