A brief note on how to work with gz (gzip) format archives.
Installation1) Working with these archives requires the gzip utility. By default it's already installed on both Linux (Debian, RedHat) and FreeBSD. But if it happens to be missing, let's install it.
CentOS/RedHat:
$ sudo yum install gzip
Debian/ubuntu:
Install it:
$ sudo aptitude install gzip
FreeBSD:
$ cd /usr/ports/archivers/gzip
$ sudo make install clean
Using it1) Extract a gz or gzip archive
$ gunzip myarchive.gz
or
$ gzip -d myarchive.gz
or using tar:
$ tar -xzf myarchive.gz
where the -z option tells us that we need to work with gzip.
2) Pack a gzip archive
$ gzip myfile1 myfile2 myfile3
In this case, a separate gz archive will be created for each specified file, named:
filename + .gz
in this example: myfile1.gz, myfile2.gz, myfile3.gz
3) Pack a gzip archive with a specified compression level
Fast method:
$ gzip -1 myfile1
High-quality method (best compression):
$ gzip -9 myfile2
Multiple files into a single archive, or tar.gzThe gzip utility works with each file separately, packing each file on its own. If you feed it several files, it will just create a separate archive for each one.
To put several files into a single archive, the tar utility is used.
That is, we first need to collect all the files into a single tar archive, and only then compress that archive. The thing is that tar itself can't compress anything - it only packs a bunch of files into one archive.
1) Creating a tar.gz archive
$ tar -cf myfile.tar myfile1 myfile2 myfile3
$ gzip myfile.tar
The output will be myfile.tar.gz
Here we first create a tar archive named myfile.tar, into which we include the files myfile1, myfile2, and myfile3; after that, we compress this archive (myfile.tar) using gzip into myfile.tar.gz
2) Extracting tar.gz
$ gunzip myfile.tar.gz
$ tar -xf myfile.tar
Here, using the gzip utility (gunzip), we first decompress the myfile.tar.gz archive, getting a single myfile.tar file; then we extract myfile.tar into separate files.
Comments