ORIGINAL PROBLEM: I would like to sync the folder ~/.maxima and all it's *.ini files to another folder, without copying/syncing its' folders/subdirectories.
Recently I have learned two new rsync options: 1) --exclude/include; 2) --prune-empty-dirs.
One can complete the above job with --exclude/include:
Method01
Code:
rsync -Sai -Eu --stats --exclude binary --exclude *.txt /${MYHOME}/.maxima /${REMOTE}/${MYHOME}
cd+++++++++ .maxima/
>f+++++++++ .maxima/am.ini
>f+++++++++ .maxima/pm.ini
>f+++++++++ .maxima/pm2.ini
Number of files: 4 (reg: 3, dir: 1)
For this small situation method01 works. But what about a more versatile solution for a more complex directory structure containing more types of files? For this we need --prune-empty-dirs:
Method02:
Code:
$ rsync -Sai -Eu --stats --include *.ini --prune-empty-dirs -f "+ */" -f "- *" /${MYHOME}/.maxima /${REMOTE}/${MYHOME}
cd+++++++++ .maxima/
>f+++++++++ .maxima/am.ini
>f+++++++++ .maxima/pm.ini
>f+++++++++ .maxima/pm2.ini
Number of files: 9 (reg: 3, dir: 6)
Number of created files: 4 (reg: 3, dir: 1)
Number of deleted files: 0
Number of regular files transferred: 3
#RSYNC manual file:
3155-3157) The combination of "+ */", "+ *.c", and "- *" would include all
directories and C source files but nothing else (see also the
--prune-empty-dirs option)
1801-1803) -F option is a shorthand for adding two --filter rules to your command.
This worked quite well. The '+' in '-f "+ */"' means include and the '*/' means directories(recursive). In -f "- *", the "-" means exclude and the "*" means any files.
But can't --prune itself include *.ini files also?
Method03:
Code:
$ rsync -Sai -Eu --stats --prune-empty-dirs -f "+ */" -f "+ *.ini" -f "- *" /${MYHOME}/.maxima /${REMOTE}/${MYHOME}
This is as effective as method02, but more concise.
But what if I had made some unwanted files on the destination(e.g. text.txt)? rsync's --prune-empty-dirs is also compatible with "--delete"! And remember, we don't need the "--no-r" option, thus no need to slavishly annex "--dirs" after "--delete":
METHOD04:
Code:
$ rsync -Sai -Eu --stats --delete --prune-empty-dirs -f "+ */" -f "+ *.ini" -f "- *" /${MYHOME}/.maxima /${REMOTE}/${MYHOME}
*deleting .maxima/text.txt/
.d..t...... .maxima/
My personal favorite is METHOD04. Hope some of you can better understand rsync's --prune-empty-dirs versatility!