tar a directory and only include certain file types
Solution 1
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
Solution 2
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=-
Solution 3
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.
Related videos on Youtube
sbuck
Updated on September 17, 2022Comments
-
sbuck almost 2 years
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
-
sbuck over 14 yearsNote 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. -
Dennis Williamson over 14 yearsOn my system with GNU
tar
version 1.22, the-I
option is used to specify a compression program.
-