How to Extract (Unzip) Files in Linux

Extracting or uncompressing files is an essential task on Linux. It can seem complicated due to the vast number of different types of compressed files prevalent on Linux and the various Linux GUI and command-line utilities available.

Compressed File Types in Linux

Common compressed file types in Linux include:

  • .zip – a .zip file is an archived file that contains one or more files compressed or “zipped” with ZIP compression.
  • .tar a .tar file (abbreviation for Tape Archive), often referred to as a tarball, puts multiple files together. Contrary to popular belief, however, a tarball does not decrease the size of these files as there is no compression involved.
  • .gz – a .gz file is created by the gzip compression utility. The gzip compression utility can only compress one .gz file.
  • .bz  and .bz2 – a .bz  and a .bz2 file are a file compressed with Bzip compression.
  • .xz – a .xz file is an archive compressed using XZ compression
  • .lzma – a .lzma file is an archive of files compressed with LZMA (Lempel-Ziv-Markov chain Algorithm) compression.
  • .rar – a .rar file is an archive that contains one or more files compressed with RAR compression.

Extracting Files via the GUI

Archive Manager

The Archive Manager, formerly known as File Roller, is the standard file archiver of the GNOME desktop environment. It supports multiple formats.

Install the Archive Manager Utility

If the Archive Manager utility is not installed on your Linux distro, you can easily install it.

For Ubuntu/Debian-based systems:

# apt install file-roller

For RHEL/CentOS-based systems:

# yum install file-roller

For Arch-based systems:

# pacman -S file-roller
Enter 'pacman -S file-roller' to install the Acrchive Manager on Arch-based distros.
Enter ‘pacman -S file-roller’ to install the Archive Manager on Arch-based distros.

To install the Archive Manager on openSUSE-based systems:

# zypper install file-roller

Extract a file using the Archive Manager Utility

In this example, we’ll extract kdeneon.tar.lzma using the Archive Manager utility.

  1. Using the File Manager, navigate to the folder containing kdeneon.tar.lzma.
  2. Right-click kdeneon.tar.lzma and select Open with Archive Manager.

    Right-click the file you want to uncompress, and select Open With Archive Manager.
    Right-click the file you want to uncompress and select Open With Archive Manager.
  3. Click Extract in the upper-left-hand corner of the Archive Manager window.

    Click the Extract button in the upper-left-hand corner of the window.
    Click the Extract button in the upper-left-hand corner of the window.
  4. Navigate to the directory where you want to extract the file and select the Extract button in the upper-right-hand corner.
  5. After the file has been extracted, select the Show the Files option.

    Select the Show the Files option
    Select the Show the Files option
  6. The extracted file, kdeneon.tar, is in the requested directory.

    The extracted file, kdeneon.tar, is in the requested directory.
    The extracted file, kdeneon.tar, is in the requested directory.

(ARK) – KDE

Ark is a KDE-based GUI Linux tool used to compress and decompress files.

Install Ark

If the Ark utility is not installed on your Linux distro, you can easily install it.

For Ubuntu/Debian-based systems:

# apt install ark
Enter 'apt install ark' to install Ark on your system.
Enter ‘apt install ark’ to install Ark on Debian/Ubuntu-based distros.

For RHEL/CentOS-based systems:

# yum install ark

For Arch-based systems:

# pacman -S ark

For openSUSE-based systems:

# zypper install ark

Extract a file with Ark

In this example, we’ll extract the archive, dtrx-master.zip, using the Ark.

  1. Using the File Manager, navigate to the folder containing dtrx-master.zip.

    Navigate to the folder containing the compressed file you want to extract.
    Navigate to the folder containing the compressed file you want to extract.
  2. Right-click the file and select the Open with Ark. Be patient while the compressed file is loaded into Ark.
  3. Click the Extract button in the upper-left-hand corner of the Ark window.

    In the upper-left-hand corner of your window, click Extract.
    In the upper-left-hand corner of your window, click Extract.
  4. Navigate to the directory where you want to extract the file and select Extract next to the Name box in the lower-right-hand corner.

    Click the Extract button in the lower-right-hand corner to extract the compressed file.
    Click the Extract button in the lower-right-hand corner to extract the compressed file.
  5. The file, dtrx-master.zip, was successfully extracted.

    The file was successfully extracted
    The file was successfully extracted

Other Linux GUI Tools to Uncompress Files

In addition to Archive Manager and Ark, there are many other tools available for Linux users to compress and uncompress files. Some popular ones are:

  • PeaZip
  • DAR
  • Engrampa
  • 7-Zip
  • Xarchiver
  • Arqiver

Uncompressing files via the Command Line

There are multiple command-line utilities for extracting and uncompressing files.

The unzip Command Line Tool

unzip Command Purpose, Syntax, and Options

The unzip command lists, tests and extracts compressed files in a .zip archive

# xz [options] [filenames]

We will use the following unzip options in our example:

  • -v – verbose. List files unzipped and show diagnostic information.

Real-Life Scenario – Extract a File Using the unzip Command

In this scenario, we’ll extract all files from the sample.zip file using the unzip command.

  1. Open the terminal in the directory where the .zip file, sample.zip, exists.
  2. Enter the following command to extract the files contained in the .zip file.
    # unzip -v sample.zip
  3. After the unzip command completes, we can see the extracted files in the directory using the ls -AL command.
    # ls -AL sample-mpg-file.mpg
  4. Close the terminal.

    The unzip command extracted the file sample-mpg-file.
    The unzip command extracted the file sample-mpg-file.

tar Command Line Tool

The tar command is resident on all Linux distros and allows users to extract/uncompress a wide variety of files, in addition to .tar files. A few of these file types are gzip, bzip2, lzip, lzma, lzop, and xz.

tar Command Purpose, Syntax, and Options

The tar command is an archiving utility resident on all Linux distros that allows the archiving and unarchiving files and directories. The syntax for the tar command is:

# tar [options][archive-file] [file or dir to be archived]

The tar command options we’ll use in our real-life scenario are:

  • -x this tells tar to extract the contents of the file.
  • -v verbose (using the -vv option provides a detailed output of the extraction).
  • -f tar will use the file ‘filename’ as the tar archive to extract.

Real-Life Scenario – Extract a File Using the tar Command

In this scenario, we’ll extract all files from the sample.tar file using the tar command.

  1. Open the terminal in the directory where the .tar file, sample.tar, exists.
  2. Enter the following command to extract the files in the .tar file.
    # tar -xvv-f sample.tar
  3. After the tar command completes, we can see the extracted files in the directory using the ls -AL command.
    # ls -AL sample.txt
  4. Close the terminal.
The tar command extracted the file sample.txt from the sample.tar file.
The tar command extracted the file sample.txt from the sample.tar file.

gunzip Command Line Tool

The gunzip command compresses or expands a file or list of files. It works with .gz, .z, _z, -gz, -z, .Z, .taz. or.tgz extensions.

gunzip Command Purpose, Syntax, and Options

The gunzip command allows Linux users to decompress files created by gzip, zip, compress, or pack.

# gunzip [options ] [-S suffix] [ filename ]

We will use the following gunzip options in our example:

  • -v -verbose output. Display the name and percentage reduction for each file compressed or decompressed.
  • -f – force decompression.

Real-Life Scenario – Extract a File Using the gunzip Command

In this scenario, we’ll extract all files from the blue.txt.gz file using the gunzip command.

  1. Open the terminal in the directory where the .gz file, blue.txt.gz, exists.
  2. Enter the following command to extract the files contained in the .gz file.
    # gunzip -vf blue.txt.gz
  3. After the gunzip command completes, we can see the extracted files in the directory using the ls -AL command.
    # ls -AL blue.txt
  4. Close the terminal.

    Use gunzip to extract .gz files.
    The gunzip command extracted the file blue.txt.gz.

The bunzip2 Command Line Tool

The bunzip2 command is used to decompress .bz2, .bz, .tbz2, .tbz, and .bzip2 files.

bunzip2 Command Purpose, Syntax, and Options

The bunzip2 command decompresses all specified files. If the Linux command bzip2 did not create the files, they’ll be ignored and a warning issued.

# bunzip2 [options] [filenames]

We will use the following bunzip2 options in our example:

  • -v – verbose. Alert the Linux user when files have been successfully extracted.

Real-Life Scenario – Extract a File Using the bunzip2 Command

In this scenario, we’ll extract all files from the techobservatory.bz2 file using the bunzip2 command.

  1. Open the terminal in the directory where the .bz2 file, techobservatory.bz2, exists.
  2. Enter the following command to extract the files contained in the .bz2 file.
    # bunzip2 -v techobservatory.bz2
  3. After the bunzip command completes, we can see the extracted files in the directory using the ls -AL command.
    # ls -AL techobservatory
  4. Close the terminal.

    The bunzip2 command extracted the file techobservatory.gz.
    The bunzip2 command extracted the file techobservatory.bz2.

The xz Command Line Tool

The xz command is a Linux data compression command-line utility used to compress and decompress files.

xz Command Purpose, Syntax, and Option

The xz command lists, tests, and extracts compressed files in .xz or .lzma formats.

# xz [options] [filenames]

We will use the following xz options in our example:

  • -d – decompress the file(s)
  • -v – verbose

You can also use the unxz command to decompress .xz and .lzma files.

Real-Life Scenario – Extract/Uncompress a File Using the xz Command

In this scenario, we’ll extract all files from the techobservatory.xz file using the xz command.

  1. Open the terminal in the directory where the .xz file, techobservatory.xz, exists.
  2. Enter the following command to extract the files contained in the .xz file.
    # xz - dv techobservatory.xz
  3. After the xz command completes, we can see the extracted files in the directory using the ls -AL command.
    # ls -AL techobservatory
  4. Close the terminal.

    The xz command extracted the file techobservatory.
    The xz command extracted the file techobservatory.

Commands Used In This Article

  • ls – list contents of a directory.
  • apt – Debian- and Ubuntu-based command-line interface for the package management system.
  • zypper – command-line package manager for installing, updating, and removing packages on openSUSE-bases systems.
  • pacman – package manager to install applications on Arch-based systems.
  • yum – (Yellow Dog Update Modifier) – package manager to install applications and packages on RHEL- and CentOS-based distros.
  • tar – extract a tarball.
  • bunzip2 – extract/uncompress a file ( bz format).
  • gunzip – extract/uncompress a file ( gzip format).
  • unzip – extract/uncompress a file ( zip format).
  • xz – extract/uncompress a file ( xz format).

Was this article helpful?

Leave a Comment