How to exclude files from TAR archive using regular expressions?
You can use some additional tools like find
and egrep
:
find directory/ -type f -print | egrep -v '[0-9]+x[0-9X]+\.jpg' | tar cvfz directory.tar.gz -T -
The drawback of the above mentioned method is that it will not work for all possible file names. Another opportunity is to use the built-in exclude functionality of tar
:
tar -czvf directory.tar.gz --exclude='*x*X*.jpg' directory
Unfortunately the second method does not work with regular expressions, but only with wildcards.