The tar file type is used to combine multiple files into a single archive. Tar actually means "tape archive," because tar's original purpose was to be used on tape backups - that should tell you how old this format is. Linux systems still use the tar format, and it continues to enjoy widespread use to this day.

Tar files, with the extension .tar, are often called "tarballs." These files will preserve the Linux file permissions and can combine any number of files into the single archive, but they don't apply any compression or space savings. However, compression can be easily applied to the tar file, resulting in extensions like .tar.gz in the case of gzip compression, or .tar.xz for xz compression.

In this guide, we'll show how to open tar files on command line and via GUI. This will include tar files with various compression applied to the archive. Check out the examples below to find out how.

In this tutorial you will learn:
  • How to open tar file via GUI
  • How to open tar file via command line
Extracting tar file on Linux
Extracting tar file on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software tar
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Open tar file via GUI


SUBSCRIBE TO NEWSLETTER
Subscribe to our NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


Various desktop environments like GNOME, KDE, Xfce, etc are going to have different looking menus. However, the process for opening a tar file is very similar across all types of GUIs. The following instructions covers GNOME, but you should be able to apply them to whatever environment you're using.

  1. In your environment's file manager, navigate to the location of your tar file that you want to open. Then, right click on the file and use either "Extract Here" to extract the contents in your present location, or "Extract To" to pick some other destination.
  2. Choose Extract Here to extract all files to the current directory
    Choose Extract Here to extract all files to the current directory
  3. Alternatively, you can open the tar file with your environment's archive manager. The simplest way to do this is by double clicking the file. This will allow you to browse the archive's contents, as well as extract them individually.


  4. Opening the tar file with archive manager to view the contents and extract them
    Opening the tar file with archive manager to view the contents and extract them
  5. The process is exactly the same for tar files with compression, such as .tar.gz, .tar.bz2, and others.
  6. Extracting compressed tar files is the same process as regular tar files
    Extracting compressed tar files is the same process as regular tar files


Open tar file via command line

Use the following examples to open tar files on the Linux command line.

  1. Extracting the contents of a tar file is very easy, and can be done with the -x (extract option). You'll also have to include the -f (file) option to indicate to tar that you will specify the location of the file. Use the following syntax to extract the contents of a tar file.
    $ tar -xf archive.tar
    
  2. You can also add the -v (verbose) option to see the extraction progress.
    $ tar -xvf archive.tar
    
  3. Note that you don't need to add any extra options to extract files from a compressed tar file.
    $ tar -xf archive.tar.gz
    $ tar -xf archive.tar.bz2
    $ tar -xf archive.tar.xz
    etc...
    
  4. To list the contents of a tar file, use the -t (list) option.
    $ tar -tf archive.tar
    file1.txt
    file2.txt
    file3.txt
    
  5. Once you've seen what files are contained within the tar archive, you can extract them individually by specifying which files to extract.
    $ tar -xf archive.tar file1.txt file2.txt
    
  6. You can also specify a wildcard in your command with the --wildcards option.
    $ tar -xf archive.tar --wildcards '*.txt'
    

  7. SUBSCRIBE TO NEWSLETTER
    Subscribe to our NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


  8. If you want to extract files to some location other than your present working directory, use the -C option and specify the path.
    $ tar -xf archive.tar -C /path/to/directory
    

That should be all you need to know when it comes to extracting tar files via command line. Check out the man page for further examples.

$ man tar

Closing Thoughts

In this guide, we saw how to extract the contents of a tar archive via command line and GUI on Linux. This is a common task for most Linux users, as tar files are widespread and you're bound to come across them sometimes. Regardless of your desktop environment or type of tar file you're working with, it's very easy to extract their contents.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.