Skip to content
Advertisement

Complex rsync filtering (includes and excludes)

I got directories and files that look like this

JavaScript

I only want to copy the 20170409_*/schedule, 20170410_*/schedule, 20170411_*/schedule folders and contents.

This mostly works:

JavaScript

However this also copies the following:

JavaScript

How do I omit the files and the dateTimeFolders I haven’t included and only get the dateTimeFolder’s schedule folder that I have included?

Advertisement

Answer

If I understand the situation correctly, you need to add the option --prune-empty-dirs (in short, -m) to your command. Those directories are not matched by the exclude rule which exludes their children, so they are copied by default. -m prevents this. If you want to prevent other files to be copied, you must add specific exclude rules for them. For instance, the files 1.txt, 2.txt and so on can be excluded by --exclude=/*.txt. All in all, your command should look as follows:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement