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
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.
- Using the File Manager, navigate to the folder containing kdeneon.tar.lzma.
- Right-click kdeneon.tar.lzma and select Open with Archive Manager.
- Click Extract in the upper-left-hand corner of the Archive Manager window.
- Navigate to the directory where you want to extract the file and select the Extract button in the upper-right-hand corner.
- After the file has been extracted, select the Show the Files option.
- 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
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.
- Using the File Manager, navigate to the folder containing dtrx-master.zip.
- Right-click the file and select the Open with Ark. Be patient while the compressed file is loaded into Ark.
- Click the Extract button in the upper-left-hand corner of the Ark window.
- 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.
- The file, dtrx-master.zip, 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.
- Open the terminal in the directory where the .zip file, sample.zip, exists.
- Enter the following command to extract the files contained in the .zip file.
# unzip -v sample.zip
- 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
- Close the terminal.
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.
- Open the terminal in the directory where the .tar file, sample.tar, exists.
- Enter the following command to extract the files in the .tar file.
# tar -xvv-f sample.tar
- After the tar command completes, we can see the extracted files in the directory using the ls -AL command.
# ls -AL sample.txt
- Close the terminal.
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.
- Open the terminal in the directory where the .gz file, blue.txt.gz, exists.
- Enter the following command to extract the files contained in the .gz file.
# gunzip -vf blue.txt.gz
- After the gunzip command completes, we can see the extracted files in the directory using the ls -AL command.
# ls -AL blue.txt
- Close the terminal.
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.
- Open the terminal in the directory where the .bz2 file, techobservatory.bz2, exists.
- Enter the following command to extract the files contained in the .bz2 file.
# bunzip2 -v techobservatory.bz2
- After the bunzip command completes, we can see the extracted files in the directory using the ls -AL command.
# ls -AL techobservatory
- Close the terminal.
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.
- Open the terminal in the directory where the .xz file, techobservatory.xz, exists.
- Enter the following command to extract the files contained in the .xz file.
# xz - dv techobservatory.xz
- After the xz command completes, we can see the extracted files in the directory using the ls -AL command.
# ls -AL techobservatory
- Close the terminal.
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).