Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Similar to this question and this question I'd like to make a single compressed tar file (files.tar.gz) that contains all the php files in my webroot and all it's subdirectories, maintaining folder structure. My webroot is called 'public_html'.

I have not tried anything yet because I'm not sure where to start. The second question that I linked actually comes pretty close to what I'm looking for, but it makes each found file a separate GZ, if I read it right.

Actually, the monolithic nature of the tar is more important to me than the compression of gzip. I just want to pull this file onto my windows machine where I can search through it with the tools I am used to.

share|improve this question
    
I think I need to check my facts. I just tested find . -name '*.html' -print | xargs echo in my own webroot. it prints a single line. Thus example 2 you linked to creates a single file. –  Hennes Nov 5 '12 at 16:01
add comment

1 Answer

up vote 3 down vote accepted

find -iname '*.php' -print0 | xargs -0 tar -rf php_backup.tar

This uses the second answer you linked to, but replaces the -c with -r

From man tar:

-c      Create a new archive containing the specified items.
-r      Like -c, but new entries are appended to the archive.  Note that
        this only works on uncompressed archives stored in regular files.
        The -f option is required.

An other option would be to replace the -print0 with -exec. I think that will be more efficient, but it might break if you have thousands or ten of thousands of files.

[Edit]

1) The -print0 and -0 after xargs are only needed if you have inconvenient separators in your filenames. (read names with spaces). You might not need those.

2) I checked the command again and tested it. find /public_www -name '*.php' -print | xargs feeds a single line to xargs. Thus the example you linked to translates to something like xargs -0 tar -cf docs.tar *.php and should also work.

share|improve this answer
    
Thanks. I tried your first version and as far as i can tell it worked perfectly, but it's good to have the additional info for the next user. –  TecBrat Nov 5 '12 at 16:18
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.