Rsync Pattern to Include All Files of Specific Patterns and Exclude the Rest, from All Subdirectory Tree

I mean to rsync some files of a subdirectory tree at dir1.

I am using

[dir1]$ rsync --itemize-changes --recursive --update --times --include-from="rsync_include.dat" --exclude="*" --dry-run ./ remote:~/dir1/

The rules are as follow, in this order.

  1. Include subdirs dir11 and dir12 at level 1.
  2. Exclude the rest at level 1.
  3. Within dir11 and dir12, include all files *.cc, *.txt in the subtrees.
  4. Within dir11 and dir12, exclude all other files.
  5. Within dir11 and dir12, include some specific subtrees (at possibly various levels), with all their contents.

I am not hitting the nail in the head with the proper combinations of single, double and triple asterisks, plus/minus signs, trailing backslashes, and rules order in my rsync_include.dat.

What would the correct contents be?

Among all I tried, I am posting below the current state of my rsync_include.dat. Among others, it did not match file classes/src/TEST/classes_test.cc, which had a later date in ./ than in remote:~/dir1/, and therefore I want it to be rsynced. In this case, I am looking for a pattern that would match that file without me having to enter + classes/src/TEST/*.cc, since there might be other *.cc at various depths and branches.

+ classes/
+ sanitizers/
- ***/.cproject
+ **/*.cc
+ ***/*.cc
+ **/*.cpp
+ **/*.dat

- */
- **/
2
Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article