How to tar certain file types in all subdirectories?

user1566515 picture user1566515 · Sep 11, 2013 · Viewed 98.3k times · Source

I want to tar and all .php and .html files in a directory and its subdirectories. If I use

tar -cf my_archive *

it tars all the files, which I don't want. If I use

tar -cf my_archive *.php *.html

it ignores subdirectories. How can I make it tar recursively but include only two types of files?

Answer

DeeDee picture DeeDee · Sep 11, 2013

find ./someDir -name "*.php" -o -name "*.html" | tar -cf my_archive -T -