Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
If you really wish to operate with concatenated archives the required parameter is --ignore-zeros according to (…) – anttir Jun 6 '14 at 7:38
up vote 4 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

share|improve this answer

You must log in to answer this question.

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