How to Extract a .gz File or directory in Linux using command prompt / terminal / shell / bash

 In blog, linux

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.

gunzip extract gz file in linux

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.

gunzip with verbose extract gz-archive linux

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


	
gunzip keep both files linux

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
gunzip view details about gzip archive

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.

gzip  file_name.txt
gzip gz a file create gz archive linux

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
Recent Posts

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Start typing and press Enter to search

laravel framework cheat sheet