The following is a snippet from a script I have that tries
to tar up all php files in a subdir. It tries to use the ‘–include’ parameter
but does not seem to work (output is from ‘set -x’ in bash)
+ find . -name '*.php'
./autoload.php
./ext/thrift_protocol/run-tests.php
./protocol/TBinaryProtocol.php
...
./transport/TTransportFactory.php
+ tar -cvjf my.tar.bz2 '--include=*.php' .
+ set +x
The find found several php files but tar does not seem to see them. If I take out the --include all files are tarred.
I know I can use find to feed a list
(find . -name '*.php' -print0 | tar -cvjf "my.tar.bz2" --null -T -), but whats wrong with the --include param?
Actually I just looked into
tar(1)on my freebsd system and I found an –include option (earlier I had looked on some old man page online). The--includeoptions is quite powerful. Here are some examplesThese are the files
Simple tar, archive everything
Archive only C files
So what is probably wrong in your script is that you give tar
.instead of.*as the last argument.EDIT
I have tried it and was surprised. The behavior of
tar(1)is unexpected but (I believe) intended. The man page says:So when you specify the pattern it filters out any directories that don’t match it. So if your directories don’t happen to have that extension (it’s valid but uncommon) it won’t descend into them (even if deep inside there might be “interesting” files).
So in conclusion I believe it would be best to use another way to recursively enumerate + filter files.