How to Extract Tar Files in Linux? [2 Best Methods]


To extract tar files in Linux, you can try the following methods:

  • To extract tar files using the command line interface:
    • For a .tar.xz file, run the tar -xf archive_name.tar.xz command for extraction.
    • When dealing with a .tar file, employ tar -xf archive_name.tar to open.
    • To extract a .tar.gz file, utilize tar -xzf archive_name.tar.gz effectively.
    • For unpacking a .tar.bz2 file, execute tar -xjf archive_name.tar.bz2.
  • With GUIs like Archive Manager, just click and choose where to extract, making it easy to open files without typing commands.

Extracting TAR files in Linux can sometimes lead to errors such as “File Not Found”, “Permission Denied”, “Not a TAR Archive”, “Archive Is Corrupt”, and issues with gzip format. These problems are often fixable by checking locations, permissions or ensuring correct commands and file integrity.

Extracting tar files in Linux can seem tricky, especially if you’re new to using the command line or graphical interfaces. But don’t worry, there’s a simple way to do it, and this post is here to guide you through each step. Whether you’re dealing with a .tar.xz, .tar, .tar.gz, or .tar.bz2 file, I’ll show you how to open them easily using tools you already have on your Linux system. Plus, I’ll share some tips on fixing common issues you might run into along the way. So, let’s dive in and make working with tar files in Linux a breeze

What Are Tar Files in Linux?

Tar files in Linux, commonly known as tarballs, are archives used primarily for distributing or backing up multiple files and directories as a single file. The name “tar” stands for Tape Archive, reflecting its origins as a method for writing data to sequential I/O devices like tape drives. A tar file typically has a .tar extension, indicating that it packages multiple files together without compression.

However, tar files can be compressed using additional tools such as gzip or bzip2, resulting in extensions like .tar.gz or .tar.bz2. These compressed tar files are smaller in size, making them more convenient for storage and transfer. The tar command provides functionality for creating, extracting, and managing these archives, making it a fundamental tool for file handling in Unix-like operating systems.

How to Extract Tar Files in Linux?

To extract tar files in Linux, you can use the tar command followed by specific options. For example, to extract the contents of a .tar file, you would use tar -xvf filename.tar, where -x stands for extract, -v for verbose (showing the progress), and -f specifies the filename. This command extracts the files into the current directory. If you’re dealing with a compressed file, such as .tar.gz or .tar.bz2, you would add the -z or -j option respectively, before the -f option, like tar -xzvf filename.tar.gz or tar -xjvf filename.tar.bz2.

2 Ways to Extract Tar Files in Linux

Extracting different types of tar files on Linux can be accomplished using a variety of methods. Below, I’ll detail how to extract .tar.xz, .tar, .tar.gz, and .tar.bz2 files using both command-line tools and graphical user interfaces (GUIs), ensuring you have the knowledge to handle these common archive formats efficiently.

1. Extract Tar files using the Command Line Interface (CLI)

The tar command is versatile and can handle various compression formats through different flags. Here’s how to use it for each file type:

1. Extracting .tar.xz Files

  1. Launch the Terminal by pressing Ctrl+Alt+T.
opening terminal 5
  1. Navigate to the file’s directory by running the command:
<strong>cd /path/to/directory</strong>

Replace /path/to/directory with the directory name you want to compress.

navigating to directory
  1. Run the following command to extract the file: 
<strong>tar -xf archive_name.tar.xz</strong>

Remember to replace archive_name.tar.xz with your file’s actual name.

extracting tar xz files
  1. Once the command runs successfully, use the ls command to see the extracted files.
verifying extraction of tar xz file

2. Extracting .tar Files

  1. Access the Terminal and navigate to the folder holding your .tar file.
  2. Execute the following command and press Enter:
<strong>tar -xf archive_name.tar</strong>

Replace archive_name.tar with the name of your file.

extracting tar files
  1. Use ls to view the contents now extracted from the archive.
verifying extraction of tar file

3. Extracting .tar.gz Files

  1. Open the Terminal and go to the directory containing your .tar.gz file.
  2. Type the following command:
<strong>tar -xzf archive_name.tar.gz</strong>

Ensure you replace archive_name.tar.gz with the actual file name.

extracting tar gz files
  1. After extraction, use ls to check the extracted contents.
verifying extraction of tar gz file

4. Extracting .tar.bz2 Files

  1. Access your command window and change to the directory containing your .tar.bz2 file.
  2. Enter the following command:
<strong>tar -xjf archive_name.tar.bz2</strong>

Make sure to replace archive_name.tar.bz2 with your file’s name.

extracting tar bz2 files
  1. Use ls to see the files extracted from the .tar.bz2 archive.
verifying extraction of tar bz2 file

2. Extract Tar files using Graphical User Interfaces (GUIs)

Using Archive Manager

  1. Search for Archive Manager in your applications menu and open it.
searching archive manager
  1. Click on Drop Down Menu > Open.
accessing archive manager
  1. Browse to the location of your .tar.xz, .tar, .tar.gz, or .tar.bz2 file. Select the file and click Open.
selecting archive using archive manager
  1. Click the Extract button usually located at the top or through a right-click context menu.
extracting files using archive manager
  1. Navigate to the chosen directory to ensure all files are extracted properly.

A Quick Comparison of CLI and GUI Methods

Here’s a simple table that compares the pros and cons of using Command Line Interface (CLI) tools versus Graphical User Interface (GUI) tools for extracting TAR files in Linux:

FeatureCLI ToolsGUI Tools
SpeedFast, direct commandsSlower, affected by graphical operations
Ease of UseSteeper learning curveIntuitive, user-friendly
Control & FlexibilityHigh, with various commands/optionsLower, limited by the graphical interface
AutomationEasy to automate tasksHarder to automate tasks
Learning CurveRequires familiarity with terminal commandsMinimal, mostly point-and-click
Visual FeedbackLimited, mainly text-basedHigh, with progress bars and windows
SuitabilityBest for experienced users and repetitive tasksBest for casual or first-time users

5 Common Errors When Extracting Tar Files in Linux

Extracting TAR files in Linux is usually straightforward, but sometimes you might encounter errors. Understanding these common errors can help you troubleshoot and solve problems quickly. Here are five common errors you might face when extracting TAR files in Linux with possible solutions:

  • 📂 File Not Found: When extracting a TAR file, you might encounter this error if Linux can’t locate the file. This typically occurs due to a misspelling or being in the wrong directory. Check the file’s presence in your current directory with ls or use find to locate it elsewhere.
  • 🔒 Permission Denied: This error pops up if you don’t have the necessary permissions to access the TAR file or write to the directory. You can overcome this by using sudo to execute your command with administrative rights or adjust the file or directory permissions with chmod or chown.
  • 🚫 Not a TAR Archive: If you get a message that it’s “not a tar archive,” the file could be corrupted or might not actually be a TAR file. Use the file command to check the file type. Ensure the file isn’t damaged and has the correct format.
  • 💥 Archive Is Corrupt: This message indicates the TAR file is corrupted, possibly due to an incomplete download or error during file transfer. Attempt to download or transfer the file again. If the file is crucial, look for TAR-specific repair tools, though their effectiveness can vary.
  • 🤔 gzip: stdin: not in gzip format: Encountering this error during the extraction of .tar.gz files suggests you’re using the wrong command or the file isn’t gzip-compressed. Ensure you’re using the correct command (tar -xzf for .tar.gz files) and verify the file’s compression format with the file command.

Wrapping it Up

Wrapping up this guide on how to open tar files in Linux and fix common problems, it’s clear there’s so much more to learn. In this guide, I’ve shown you how to extract various tar files in Linux using command-line and graphical interfaces and addressed common errors like file not found and permission issues. These methods and troubleshooting tips ensure you can handle archives efficiently. If you’re looking to expand your Linux skills, consider exploring topics such as automating tasks with shell scripting, managing system services and processes, and configuring network settings. These areas complement what we’ve covered, offering you a broader understanding of Linux. 

Frequently Asked Questions

  1. Can I extract multiple TAR files at once using the command line?

    Yes, you can extract several TAR files at once in the command line using a loop. For .tar.gz files, execute: for file in *.tar.gz; do tar -xzf “$file”; done. This extracts all .tar.gz files in your current directory, streamlining the process.

  2. What do I do if I encounter an error saying the TAR file is in an older format?

    Encountering an “older format” error with a TAR file is not a major issue. Most contemporary tar versions adeptly manage older formats. If problems persist, update your tar or attempt extraction on a system with a more recent tar version for better compatibility.

  3. Can I extract TAR files that are encrypted or password-protected?

    Extracting encrypted or password-protected TAR files is possible, but it requires prior decryption. While tar doesn’t natively support encryption, encrypted files with gzip, bzip2, or xz can be decrypted using tools like gpg. Decrypt your file with the correct tool and password before extraction.

  4. Is there a way to resume an interrupted extraction process?

    Resuming an extraction after an interruption is not directly feasible with tar. Should an interruption occur, you must restart the process. To improve efficiency, delete any partially extracted files and re-run the extraction. Scripts can help automate this, skipping files that were already extracted.



Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.



Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

How to Use Tar Command in Linux [16 Best Uses]

Next Post

How to Merge PDF Linux [4 Easy Methods]

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next