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.

Is it valid to do this:

{
tar -c dir1
tar -c dir2
} | cat > file.tar

Is the resulting file.tar a valid tar ball?
If not, how can I concatenate tar balls on the fly?

share|improve this question
1  
If you really wish to operate with concatenated archives the required parameter is --ignore-zeros according to (gnu.org/software/tar/manual/html_section/…) –  anttir Jun 6 at 7:38

2 Answers 2

up vote 2 down vote accepted

Yes, with a slight modification of your method.

tar supports concatenating multiple tar files together.... remember its history... it's a TAPE-ARCHIVE.... it's a data-stream, reminiscent of a spool of tape whizzing past the read/write head.... it's just blocks of data to the tar program...

From what my testing shows, you kinda have to have at least ONE tar file somewhere...

tar cf one.tar buncha files to add

From this point... you can either add more files, or append another tar (or multiple...)

tar rf one.tar even more files to fill up this pseudo tape
tar Af one.tar two.tar three.tar four.tar

Everything gets smushed into 'one.tar' in this example...

if you use the 'rf', it appends new files to the given tar (one.tar here), whereas if you use the Af, it appends one or more tar files onto the original tar file (urk! recursive tar! sticky!)

As always, the man pages are your friends. (slow, faintly glowing phosporusly green friends... but friends)

share|improve this answer

You cannot just concatenate tarballs like this, it will not behave as you would expect. You can check the contents of the tarball using:

tar tf file.tar

This would only print the contents of dir1 without dir2. To archive two directories dir1 and dir2 into file.tar, you can use:

tar cf file.tar dir1 dir2

The manual is available at http://www.gnu.org/software/tar/manual/

share|improve this answer

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.