Combine two or more compressed files

Surprisingly what Quanta posted in the comments works -- at least on my Mac!

$ echo abc > foo
$ echo cba > bar
$ gzip foo
$ gzip bar
$ cat foo.gz bar.gz > baz.gz
$ gunzip baz.gz 
$ cat baz 
abc
cba
$

I am somewhat disturbed, yet also impressed.


I guess you mean:

zcat r_TR2_2012-05-28-08-10-00.gz r_TR1_2012-05-28-08-10-00.gz| gzip -9 > joined.gz


If you have multiple compressed files .gz and you need to combine them into one file, you can use tar directly to do so. No need to uncompress and then compress them again.

You can try this:

tar cvf combined.gz.tar r_TR1_2012-05-28-08-10-00.gz r_TR2_2012-05-28-08-10-00.gz

However, you will get a file with extension .gz.tar as opposed to the known .tar.gz. To uncompress the file, you can try:

tar -xavf combined.gz.tar

The option -a is useful here (from man tar):

-a, --auto-compress
       use archive suffix to determine the compression program