That is, unfortunately not straightforwardly possible as the --exclude
family of options is not powerful enough.
One approach would be to obtain the list of objects using external program (say find
) and then use -T
switch to tell tar which files/objects should be included.
Quoting from the man page:
-T, --files-from FILE get names to extract or create from FILE
If the filenames contain special symbols (and/or spaces) I would add --null
to the tar command line; to generate the list I would also use -print0
with find -- to separate the files/dirs with NUL (\000
) character.