1. Overview
Sometimes, when working in Linux, we may have multiple Gzip files that we’d like to merge into a single Gzip file.
In this tutorial, we’ll explore some of the simple and useful and tools we can use to concatenate multiple Gzip files into one from the Linux command line.
2. Gzip Files
The Gzip file compression algorithm, which uses the .gz file extension, helps us reduce file sizes without impacting the timestamp, file ownership, or mode. We can use the gzip command to compress single or multiple files.
Here, we see the output of a gzip command along with a reduction percentage in size for the geckodriver file:
$ gzip -v geckodriver
geckodriver: 60.8% -- replaced with geckodriver.gz
3. Concatenation of Gzip Files
We can use some common commands like cat and tar to concatenate Gzip files in the Linux system.
3.1. Using the cat Command
The gzipped files can be concatenated using the cat command. Here, we’ll concatenate the files geckodriver.gz and geckodriver-linux.gz to create the file concatefile.gz:
$ cat geckodriver.gz geckodriver-linux.gz > concatefile.gz
The command ls -sh gives the details of the above files after concatenation:
$ ls -sh
total 18008
9000 concatefile.gz 5296 geckodriver-linux.gz 3712 geckodriver.gz
3.2. Using the tar Command
The tar command’s original use was for reading and writing tape archives. We can use tar to generate archive files and extract files from them. Here, we’ll create the tar file concatefile.tar to contain our two Gzip files:
$ tar -cvf concatefile.tar geckodriver.gz geckodriver-linux.gz
a geckodriver.gz
a geckodriver-linux.gz
The command ls -sh gives the details of the above files after concatenation with the tar command:
$ ls -sh
total 18016
9008 concatefile.tar 3712 geckodriver-linux.gz 5296 geckodriver.gz
4. Conclusion
In this article, we have explored how cat and tar commands are useful in concatenating multiple Gzip files in Linux.