Linux / UNIX command to open .gz files

by on October 4, 2007 · 19 comments· LAST UPDATED October 4, 2007

in , ,

Q. I have download files from the Internet. Each file has .gz extension. How do I open .gz files under Linux?

A. You need to use gzip / gunzip program. It is a software application used for file compression. It is based on the DEFLATE algorithm, which is a combination of LZ77 and Huffman coding. DEFLATE was intended as a replacement for LZW and other patent-encumbered data compression algorithms

How do I extract a gz file?

Use guzip command as follows:
$ gunzip file.gz
$ gzip -d file.gz
To see new file, enter:
$ ls -l

How do I extract a tar.gz or .tgz file?

Files with extension tar.gz or .tgz are tar files compressed with gzip. On Unix system extract them with following command:
$ gunzip < file.tar.gz | tar xvf -
$ gunzip < file.tgz | tar xvf -

If you have GNU tar (Linux system) you can use the z option directly:
$ tar xvzf file.tar.gz
$ tar xvzf file.tgz

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 19 comments… read them below or add one }

1 Carolanne October 15, 2007 at 1:30 pm

I can extract a .gz file using WinZip but how do I open a .gz file under Windows XP?


2 Balakrishna Bhat March 17, 2009 at 3:22 pm

I have some softwares downloaded from internet and few copied from Chip Magazine’s data dvds. I have dual-boot system[Windows xp home and ubuntu 8.10].I do not have much experience about computers and want to install few softwares which are in tar.gz formats and few are in tar.bz2 formats. I do not know how to install them-Only the deb or i386 formats are can be installed through Gdebi installer.Will you suggest me how to?


3 Luciano July 21, 2009 at 12:39 pm

Nice blog!!
Keep it up!!


4 Balakrishna Bhat July 21, 2009 at 1:20 pm

Really nice one-exactly the one needed.


5 kamal September 19, 2010 at 1:56 pm

It’s giving me following error :

root@server [/10gR2_db]# gzip -d 10201_database_linux_x86_64.cpio.gz

gzip: 10201_database_linux_x86_64.cpio.gz: unexpected end of file
root@server [/10gR2_db]


6 ahmadalza September 10, 2011 at 1:29 pm

#mv 10201_database_linux_x86_64.cpio.gz 10201_database_linux_x86_64_cpio.gz


7 sai November 30, 2011 at 6:45 am

thank you for the help. really appreciate it.


8 namrata June 29, 2012 at 4:13 pm

tar: error i not recoverable : existing now …
this is the error m getting anyone have idea how do i resolve this


9 abnehmentipps August 10, 2012 at 8:04 am

That was useful. Just a note: too often the compressed file has the extension .tar (not in gzip format). Then just use tar xvf file.tar

Many tx!


10 waleed November 10, 2012 at 12:03 pm

gunzip: configuration_files.tar.gz: unexpected end of file


11 srinadh October 2, 2013 at 8:33 am

this problem with the zip file,it must be corrupted during ftp


12 saeid January 23, 2013 at 4:25 am

Thank You Very Very Much
Because Site & You


13 Priyanka April 6, 2013 at 3:11 am

if we need to gzip a folder and all the files inside the folder ,
gzip -d works ?


14 Asif April 17, 2013 at 6:09 am

Is there any command in unix to extract .deflate files?


15 amin khalaj June 26, 2013 at 6:59 am

thank you. it was really helpful.


16 Anand October 10, 2013 at 12:20 pm

30-35% of my troubleshooting queries on google lands me here at and believe me 30-35% is a lot considering the whole www. You guys have done an excellent job creating these really helpful articles.
Keep it up.


17 nixCraft October 10, 2013 at 5:45 pm

Thanks for the kind words. We appreciate your support :)


18 yoges May 30, 2014 at 1:11 pm

It work :) thanks ….


19 smith June 30, 2014 at 12:21 pm

Really Really very helpful


Leave a Comment

Tagged as: , , , , , , , , , , , ,

Previous Faq:

Next Faq: