How To Open a Tar.gz File In Linux / Unix

I‘ve received a file called date.tar.gz. How do I open/extract/unpack a tar.gz file on Linux or Unix like operating systems using shell prompt?

A .tar.gz (also .tgz) file is nothing but an archive. It is a file that acts as a container for other files. An archive can contain many files, folders, and subfolders, usually in compressed form using gzip or bzip2 program on Unix like operating systems.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements tar
Est. reading time 4 mintues

Say hi to tar command line tool

You need to use the tar command which can create and manipulate archive files in .tar.gz under Unix like operating systems. Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following to open and extract a .tar.gz file:

tar -zxvf data.tar.gz
tar -zxvf /path/to/archive.tar.gz
tar -zxvf archive.tgz

Where options are as follows:

  • -z : Uncompress the resulting archive with gzip command.
  • -x : Extract to disk from the archive.
  • -v : Produce verbose output i.e. show progress and file names while extracting files.
  • -f data.tar.gz : Read the archive from the specified file called data.tar.gz.

How To Open a Tar.gz File In Linux / Unix System

By defaults files will be extracted into the current directory. To change the directory use -C option. In this example, extract files in /data/projects directory:

tar -zxvf data.tar.gz -C /data/projects

To view a detailed table of contents (list all files) for this archive, enter:

tar -tzvf data.tar.gz

Sample outputs:

-rw-r--r-- root/root      2981 2012-01-11 03:24 etc/adduser.conf
-rw-r--r-- root/root      6302 2012-01-11 04:46 etc/ca-certificates.conf
-rw-r--r-- root/root      2969 2011-01-31 00:14 etc/debconf.conf
-rw-r--r-- root/root       600 2010-11-22 02:46 etc/deluser.conf
-rw-r--r-- root/root       346 2010-12-05 20:23 etc/discover-modprobe.conf
-rw-r--r-- root/root      8661 2011-12-31 21:45 etc/ffserver.conf
-rw-r--r-- root/root      2940 2011-01-24 00:26 etc/gai.conf
-rw-r--r-- root/root       899 2009-08-31 12:51 etc/gssapi_mech.conf
-rw-r--r-- root/root      4794 2010-09-30 17:44 etc/hdparm.conf
-rw-r--r-- root/root         9 2006-08-07 22:44 etc/host.conf
-rw-r--r-- root/root       145 2010-08-26 08:09 etc/idmapd.conf
-rw-r--r-- root/root       882 2010-05-07 15:33 etc/insserv.conf
-rw-r--r-- root/root     31393 2007-10-21 13:50 etc/jwhois.conf
-rw-r--r-- root/root       144 2012-01-11 04:55 etc/kernel-img.conf
-rw-r--r-- root/root      1180 2009-04-24 02:55 etc/kerneloops.conf
-rw-r--r-- root/root        34 2012-01-11 03:23 etc/
-rw-r--r-- root/root      3587 2010-04-10 03:54 etc/lftp.conf
-rw-r--r-- root/root        26 2010-08-14 20:40 etc/libao.conf
-rw-r--r-- root/root       191 2010-06-18 19:54 etc/libaudit.conf
-rw-r--r-- root/root       599 2009-02-19 17:27 etc/logrotate.conf
-rw-r--r-- root/root     15752 2009-07-25 20:43 etc/ltrace.conf
-rw-r--r-- root/root       801 2011-06-20 08:24 etc/mke2fs.conf
-rw-r--r-- root/root       624 2010-02-15 10:09 etc/mtools.conf
-rw-r--r-- root/root       513 2012-01-11 04:53 etc/nsswitch.conf
-rw-r--r-- root/root       552 2010-10-19 22:22 etc/pam.conf
-rw-r--r-- root/root      7649 2012-01-11 04:53 etc/pnm2ppa.conf
-rw-r--r-- root/root      2724 2010-08-08 01:33 etc/reportbug.conf
-rwxr-xr-x root/root       332 2012-05-05 14:14 etc/resolv.conf
-rw-r--r-- root/root      2573 2012-04-06 00:00 etc/rsyslog.conf
-rw-r--r-- root/root      8596 2010-05-26 23:02 etc/sensors3.conf
-rw-r--r-- root/root      7093 2010-12-26 17:23 etc/smartd.conf
-rw-r--r-- root/root      2089 2012-02-26 03:35 etc/sysctl.conf
-rw-r--r-- root/root       645 2009-03-25 16:35 etc/ts.conf
-rw-r--r-- root/root      1260 2008-05-30 11:52 etc/ucf.conf
-rw-r--r-- root/root       274 2009-11-04 03:46 etc/updatedb.conf
-rw-r--r-- root/root       571 2010-11-11 20:13 etc/usb_modeswitch.conf

file-roller : GUI tool

GNOME Archive Manager Running on my Ubuntu 20.04 LTS desktop

Archive Manager (file-rollter) is an application for managing archive files, for example, .zip or .tar files; it is designed to be easy to use. Archive Manager provides all the tools that are necessary for creating, modifying and extracting archives. Hence, you can use the Archive Manager GUI application to create, view, modify, or unpack an archive. You can start Archive Manager by clicking on
Applications menu > Choose Accessories > Archive Manager

Fig.01: Gnome Archive Manager

To open an archive:
  1. Choose File.
  2. Open to display the Open dialog.
  3. Select the archive that you want to open.
  4. Click Open.

Fig.02: Linux: Open Files With an Archive Manager

Once opened you can view or extract files. To select all files in an archive, choose Edit > Select All or press Ctrl+A. To extract files from an open archive:
Select the files that you want to extract.
  1. Choose Archive > Extract to display the Extract dialog. Alternatively click Extract in the toolbar.
  2. Select the folder where Archive Manager extracts the files.
  3. Click Extract.

Fig.03: Linux GUI Extract Files From an Archive - data.tar.gz

You learned how to untar or open .tar.gz archives on Linux and Unix-like systems using the GUI and CLI tools. Please note that you can also open GUI tools simply typing the following xdg-open command on Linux or open command on macOS/Mac OS X:
You learned how to untar or open .tar.gz archives on Linux and Unix-like systems using the GUI and CLI tools. Please note that you can also open GUI tools simply typing the following xdg-open command on Linux or open command on macOS/Mac OS X:
xdg-open linux-archive.tag.gz
open macos-tar-archive.tar.gz

See tar(1) command man page for more information:
man tar
🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 16 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig 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 VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
16 comments… add one
  • fishcooker Jun 17, 2012 @ 0:55

    can i access n edit the complicated structured tar files

  • peer Jun 30, 2012 @ 12:37

    Get the Midnight commander:

    sudo apt-get install mc

    • Shadow Jul 26, 2014 @ 4:45

      Ah been meaning to install this for the next time I have the privilage to use an ssh to fix a computer system. Thanks for the reminder.

  • Jako Dec 3, 2013 @ 6:05

    Thank you very much its super very effective

  • Steve Jul 8, 2014 @ 17:37

    Yawn. This is why linux after all these years is a waste of space. In 10 years you still haven’t managed to create a double click installer. Common fanboys hit me with your arrogant linux attitude. I don’t want to hear your explanations no one wants tar files no one wants to use a terminal and until you have a double click install with zip, rar and 7z support i will always call linux rubbish. see yah.

    • Brett Morgen Jul 21, 2014 @ 18:35

      You are dumber than Ted Kennedy the night he crashed his car and brutally shred apart and killed his date. Keep voting Democrat.

    • Shadow Jul 26, 2014 @ 4:42

      Actually it is supported and additional archieve formats can be added with ease to the linux system; many users prefer the terminal, why you may ask because it is power which cannot be met by any GUI tool which is the case on almost every operating system. Also download a .deb file and double-click it; seriously I don’t think you’ve ever had the privillage of using a unix system or linux system for that matter.

      Get a life or get a job as I see there is absolutely no reason to discourage new users simply because you are ignorant or lack the skills required to have an even primitive knowledge of the same system that runs most of world’s webservers and 99% of the world’s fastest supercomputers.

      So we’re all a bunch of fanboys; I personally have a custom kernel and my system runs even cooler under linux than Windows. I’ve logged hundreds of hours in Windows troubleshooting issues ranging from rootkits to the occassional user whom fails to understand that doubleclicking that exe file will start the installer (same thing as double-clicking a .deb file on a debian/debian-based system).

      By the time I was 18 I was an IT whom had worked on databases worth millions. If you honestly expect me to believe for even a moment that you have even experience once so ever on these systems then you are dumber than I first thought. I’ve worked alongside software engineers and systems analysts and have served as an advisor for computer systems all of these were Windows.

      Also there was a study done which showed that linux (study used Ubuntu) is more user-friendly than Windows. Now if you want to start an debate on macs I’ll have to remind you that macs are unix-based and after it took 6 months for Apple to patch only one security threat when the linux kernel can be patched in hours.

      I’m done…I don’t waste my time with trolls…

      …I have a database to write

    • eliot Dec 7, 2014 @ 16:32

      That’s a silly comment.

    • cyberoptiq May 19, 2015 @ 14:14

      It’s because of idiots like you with that mindset faded away into obscurity because they refused to learn new and emerging technologies….much like the ex-mainframer’s I used to work with at one of my prior places of employment (Chubb & Son’s, Inc. in New Jersey) who refused to want to learn Unix or any other operating system because they believed nothing could be superior to Big Iron, as mainframes are called…..after the datacenter was outsourced many of them could not find employment because of their outdated 70’s experience and technical skills and had to take jobs at Lowes, Home Depot, WalMart, KMart, and other non-technology companies….WHY???? Because they failed to stay current!! You sound just like that group of losers who had nothing to do but bash this system and that system in favor of Big Iron without thinking ahead to where the future may take them…..

    • Alex Jul 23, 2015 @ 9:22

      Mojang, remove the Steve skin! That is a stupid comment.

    • PH Oct 21, 2015 @ 18:37

      As a decade long linux user I have to say…you’re absolutely right. It’s really frustrating after all this time that a double click option isn’t available. Sorry chaps, it’s the truth.

    • The Cool Steve Feb 1, 2017 @ 22:39

      The Rule of Three is in full effect. Example:

      This guy’s a douche.

      Go spend your dads money on an expensive laptop made of glue, and enjoy double clicking on Facebook at Starbucks, douche.

      Oh yeah, by the way… this guy’s a douche.

    • Ronaldo S Jenkins May 8, 2021 @ 17:53

      You are a Clown. You are just lashing out cause you have no clue how to navigate in such a straight forward system.

  • mario Aug 31, 2014 @ 1:35

    any chance I could unzip a tar file on an android fone?

    • ayy Jun 2, 2015 @ 19:27

      install busybox if the tar command isn’t already installed

  • oscar D Jul 5, 2015 @ 14:50

    Super…using TAR is easy and was able to unpack Eclipse compiler into Linux.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum