Files compressed by gzip
can be directly concatenated into larger gzipped files.
cat file1.gz file2.gz file3.gz > combined.gz
This is a property of gzip
that is less efficient than concatenating the input files and gzipping the result:
cat file1 file2 file3 | gzip > combined.gz
A complete demonstration:
echo 'Hello world!' > hello.txt
echo 'Howdy world!' > howdy.txt
gzip hello.txt
gzip howdy.txt
cat hello.txt.gz howdy.txt.gz > greetings.txt.gz
gunzip greetings.txt.gz
cat greetings.txt
Which results in
Hello world!
Howdy world!
Notice that greetings.txt.gz
is a single file and is decompressed as the single file greeting.txt
. Contrast this with tar -czf hello.txt howdy.txt > greetings.tar.gz
, which keeps the files separate inside the tarball.