Extract GZ archive file in Linux Terminal
To extract the GZ archive to the current directory, use below command.
$ gunzip archive.gz
.gz files are compressed with gzip compression algorithm. To extract .gz files we use gunzip command is used in Linux.
if the operation is successful, nothing is shown and linux command prompt is given back to the user
Extract GZ file and see verbose output
if you want to see what happens during the unzip operation , you can user the -v parameter with the command.
# gunzip -v file_name.gz
-v stands for verbose, which shows a log of actions happening while the archive is decompressed.
Also note, after decompressing using gubzip , the GZ extention is removed from the file. so , your compressed archive is no longer available but the extracted file.
Extract GZ file keep both orginal file and new
if you want to keep the archive as well, please use the -k parameter with the command as below.
# gunzip -k file_name.gz
View information about a GZ archive file
To view information about the compressive GZ gzip file, you can use the gunzip command like below, it does not uncompress the archive but give you vital information about the archive.
gunzip -l file_name.gz
Compress a file to a GZIP archive with GZ extension
Sometimes it is required to compress a file to save space, transfer safely or for other reasons. In Linux , you can use gzip command to compress a file. e.g.
Compress a directory using gzip
On Linux, gzip is unable to compress a folder, it used to compress a single file only. To compress a folder, you should use tar + gzip, which is tar -z.
tar -zcvf outputFileName.tar.gz folderToCompress