Linux / UNIX command to open .gz files

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

ADVERTISEMENTS

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
OR
$ 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

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
21 comments… add one
  • Carolanne Oct 15, 2007 @ 13:30

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

  • Balakrishna Bhat Mar 17, 2009 @ 15:22

    Sir,
    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?

  • Luciano Jul 21, 2009 @ 12:39

    Nice blog!!
    Keep it up!!

  • Balakrishna Bhat Jul 21, 2009 @ 13:20

    Really nice one-exactly the one needed.

  • kamal Sep 19, 2010 @ 13:56

    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]
    ====

    • ahmadalza Sep 10, 2011 @ 13:29

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

  • sai Nov 30, 2011 @ 6:45

    thank you for the help. really appreciate it.

  • namrata Jun 29, 2012 @ 16:13

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

  • abnehmentipps Aug 10, 2012 @ 8:04

    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!

  • waleed Nov 10, 2012 @ 12:03

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

    • srinadh Oct 2, 2013 @ 8:33

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

  • saeid Jan 23, 2013 @ 4:25

    Thank You Very Very Much
    Because Site & You

  • Priyanka Apr 6, 2013 @ 3:11

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

  • Asif Apr 17, 2013 @ 6:09

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

  • amin khalaj Jun 26, 2013 @ 6:59

    thank you. it was really helpful.

  • Anand Oct 10, 2013 @ 12:20

    30-35% of my troubleshooting queries on google lands me here at cyberciti.biz 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.

    • 🐧 nixCraft Oct 10, 2013 @ 17:45

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

  • yoges May 30, 2014 @ 13:11

    It work :) thanks ….

  • smith Jun 30, 2014 @ 12:21

    Really Really very helpful

  • Egyptian Jun 1, 2015 @ 16:58

    cyberciti.biz is an important resource for any one wants to learn Linux. I did learn lots from your posts. Thank you for the hard working and sharing the good knowledge.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.