Can multiple .gz files be combined such that they extract into a single file? [duplicate] Can multiple .gz files be combined such that they extract into a single file? [duplicate] unix unix

Can multiple .gz files be combined such that they extract into a single file? [duplicate]


Surprisingly, this is actually possible.

The GNU zip man page states: multiple compressed files can be concatenated. In this case, gunzip will extract all members at once.

Example:

You can build the zip like this:

echo 1 > 1.txt ; echo 2 > 2.txt; echo 3 > 3.txt;gzip 1.txt; gzip 2.txt; gzip 3.txt;cat 1.txt.gz 2.txt.gz 3.txt.gz > all.gz

Then extract it:

gunzip -c all.gz > all.txt

The contents of all.txt should now be:

123

Which is the same as:

cat 1.txt 2.txt 3.txt

And - as you requested - "gunzip will extract all members at once".


In order to concatenate multiple files, try:

gzip -c 1.txt > 123.gzgzip -c 2.txt >> 123.gzgzip -c 3.txt >> 123.gz

Subsequently, gzip -dc 123.gz would be equivalent to cat 1.txt 2.txt 3.txt.