Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Following the instructions here:

I'm aiming to tar up a directory but only want to include .php files from that directory.

Given the aforementioned instructions, I've come up with this command. It creates a file called IncludeTheseFiles which lists all the .php files, then the tar is supposed to do it's job only using the files listed in IncludeTheseFiles

find myProjectDirectory -type f -print | \
egrep '(\.[php]|[Mm]akefile)$' > IncludeTheseFiles
tar cvf myProjectTarName -I IncludeTheseFiles

However, when I run this it doesn't like the I include option?

tar: invalid option -- I
share|improve this question
Note that I realize in this context it seems a little overkill creating the list of files when I could just do something like: tar cvf myProjectTarName.tar find myProjectDirectory -name '*.php' But my end goal is actually to tar up more than just .php files (ex: all php, html, inc, css, js files), which is why I am doing it the above way. – Susan Mar 30 '10 at 18:00
On my system with GNU tar version 1.22, the -I option is used to specify a compression program. – Dennis Williamson Mar 30 '10 at 18:08

This does the trick, no comparison file needed:

find myProjectDirectory -type f \( -name \*\.php -o -name \*\.js -o -name \*\.css -o -name \*\.inc \) | xargs tar -rf myProjectTarName.tar
share|improve this answer

Reading the man page for Gnu tar on my Ubuntu 8.04 system, it says:

-T, --files-from F
    get names to extract or archive from file F

It does not reference a -I option other than to mention that historically it was used to request bzip compression.

share|improve this answer

You should be able to specify stdin as the source for your filenames. Try:

find myProjectDirectory -type f -regextype posix-egrep -regex ".*/(.*\.[php]|[Mm]akefile)$ -print | \
tar cvf myProjectTarName --files-from=-
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.