Rsync only specific files and directory containing these files

Suppose I have a directory structure like

src/
src/a/
src/a/1.ocf  
src/a/1.pdf  
src/a/1.txt
src/b/
src/b/2.ocf
src/b/2.pdf
src/b/2.xls
src/c/
src/c/3.doc
src/c/3.ocf
src/c/3.txt
src/d/

Then I just want to sync only files with the * .txt extension. So, I tried using a command, for example:

#rsync -avvH --include="*/" --include="*.txt" --exclude="*" src/ dst/
sending incremental file list
./
a/
a/1.txt
b/
c/
c/3.txt
d/

Unfortunately, this command not only synchronizes the * .txt file, but also the entire directory. I do not want the 'b' and 'd' directories to be synchronized because they do not contain the * .txt file

Is there an easy way to do this?

+4
source share
1 answer

You can choose -mto trim empty directories:

rsync -avvHm --include="*/" --include="*.txt" --exclude="*" src/ dst/
+3
source

Source: https://habr.com/ru/post/1610070/


All Articles