0

Good morning, I want to transfer specific files in a directory to a remote machine while keeping the architecture of the subdirectories. Moreover, I only want to transfer files that have a peculiar extension (e.g. ".txt"). I have tried the following:

rsync -aP --include *.txt ./sourceDirectory user@hostIP:destDirectory

but it copies to the destination (destDirectory) all the files, and not only those which match the .txt pattern. Could anybody help me with such riddle?

P.S.: obviously, the directory sourceDirectory contains subdirectories where are located my .txt files.

Cyrus
  • 84,225
  • 14
  • 89
  • 153

1 Answers1

3

I used to have the same problem when rsync videos to home NAS. If you read the manual of rsync, the --include flag really means "Do not exclude". It actually has to work together with a --exclude flag.

The follow command will do your job:

rsync -aP --include="*/" --include="*.txt" --exclude="*" sourceDirectory destDirectory

The command literally means exclude everything, except for subfolders and txt file.

Taylor G.
  • 661
  • 3
  • 10