A GZ file is a compressed archive that uses the gzip compression algorithm (GNU zip). This format was created to replace compression formats on UNIX systems. It may contain multiple compressed files, directories, and stubs. This compression algorithm is more popular for compressed web pages to reduce page loading time.
The GNU zip compressed file uses
.z extension. In this article, you will learn how to decompress (Unzip or extract) a GZ file via the command line.
Extracting GZ file:
We can use
gunzip command to decompress a
.gz file on Linux and macOS systems.
.gz file is compressed with
gzip command line. That can also be used to decompress it with
gzip -d file_name.gz
Both the above commands retrieve back the original file and remove the
.gz extension from file name.
Once you have decompressed a
.gz file, it will no longer avaialble. But, if you want to keep the archive file use
--keep option with unzip command.
gzip -d -k file_name.gz
gunzip -k file_name.gz
- First, use the following command to create gzip (.gz) archive of the access.log file. Keep remembering that the below command will remove the original file.
- Above command will create a archive file named access.log.gz in current directory.
ls -l access.log.gz-rw-r--r-- 1 root root 37 Sep 14 04:02 access.log.gz
- Now use gunzip command to extract the access.log.gz file using the command. This will extract the file from the archive and remove the
In this blog post, you have learned about extracting a
.gz on Linux or macOS system using command line. You can also enable Gzip compression in Apache.