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
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| # - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
Open tar file via GUI
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.
- 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.
- 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.
- The process is exactly the same for tar files with compression, such as
.tar.bz2, and others.
Open tar file via command line
Use the following examples to open tar files on the Linux command line.
- 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
- You can also add the
-v(verbose) option to see the extraction progress.
$ tar -xvf archive.tar
- 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...
- To list the contents of a tar file, use the
$ tar -tf archive.tar file1.txt file2.txt file3.txt
- 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
- You can also specify a wildcard in your command with the
$ tar -xf archive.tar --wildcards '*.txt'
- If you want to extract files to some location other than your present working directory, use the
-Coption 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
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.