Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Following the instructions here: http://linuxdevcenter.com/pub/a/linux/lpt/20_08.html

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
add comment

3 Answers

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
add comment

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
add comment

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
add comment

Your Answer

 
discard

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.