1

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
2
  • 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.
    – sbuck
    Mar 30, 2010 at 18:00
  • On my system with GNU tar version 1.22, the -I option is used to specify a compression program. Mar 30, 2010 at 18:08

3 Answers 3

3

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
1

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.

1

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=-

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .