Open In App

How to Unrar Files in Linux

Last Updated : 21 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The RAR file format is popularly used to compress large files, thus allowing users to share and store them easily. Now, while we often see TAR and GZIP file formats in Linux, one might cross paths with RAR files too. In this article, we will learn how to unrar files in Linux in detail.

Installing the Unrar Application on Linux: A Step-by-Step Guide

To Unrar any file in Linux, we first need to install the Unrar utility. This tool can be easily downloaded from the Linux distribution's package manager. Let us look at how to install it from different distributions.

Ubuntu/Debian

sudo apt update
sudo apt install unrar

CentOS/RHEL

sudo yum upgrade
sudo yum install unrar
Installing unrar

Fedora

sudo dnf upgrade
sudo dnf install unrar

Arch Linux

pacman -Syu
pacman -S unrar

Installing unrar from source code

1. Installing build tools:

//For Debian/Ubuntu
sudo apt install build-essential


//For CentOS/RHEL
sudo yum groupinstall "Development Tools"


//For Fedora
sudo dnf groupinstall "Development Tools"


//For Arch Linux
sudo pacman -S base-devel

2. Downloading the source code:

wget https://www.rarlab.com/rar/unrarsrc-<version>.tar.gz

3. Extracting the source code:

tar -xvf unrarsrc-<version>.tar.gz
cd unrar

4. Compilation and installation:

make
sudo make install
Installing unrar from source code

Extracting RAR Files Using Command Line

Basic Syntax

The basic syntax for using unrar to extract files from the RAR archives is shown below.

unrar [option] [archive] [path]  

The Unrar application is a very effective and user-friendly tool that allows users to extract RAR files. Let us understand its usage with the implementations below.

Extracting Files

We use the 'x' option with unrar to extract files from a RAR archive.

unrar x example.rar

This will extract all the files of example.rar to the current working directory while preserving its structure.

Extracting files using unrar in linux

Extracting Files to a Specific Directory

As we saw above, the unrar utility by default extracts files into the current directory. But if required we can also extract the content of the RAR archive to a specific directory.

unrar x example.rar /home/user/documents/

To extract the files to a specific directory we need to add the path of the directory at the end of the command. In the above example, all the files from example.rar are extracted to the directory '/home/user/documents/'.

Extracting files to a specific directory

Listing the RAR File contents

We can also list the contents of the RAR archive without actually extracting them using the 'l' option with the unrar command.

unrar l example.rar

This displays all the files and directories contained in the RAR archive.

Listing the RAR file contents

Extracting Specific File

Now there can be multiple files within the RAR archive and extracting all of them can unnecessarily eat up your system memory. Thus the unrar utility also allows users to extract specific files. This can be done by listing the file names after the archive name with the unrar command as shown below.

unrar x example.rar file1 file2

This will extract only file1 and file2 from example.rar even if there are other files in the rar archive.

Testing Archive Integrity

We can also test the integrity of a RAR file without extracting it. This can done using the 't' option with the unrar command.

unrar t example.rar

The above command tests the RAR archive and reports any error or corrupt files.

Extracting Password Protected files

Some RAR files can be password-protected for security reasons. In such cases, we can use the '-p' option followed by the password to extract its contents.

unrar x -p<PASSWORD> example.rar

Replace <PASSWORD> with the password of the RAR archive. If the password is not specified the unrar tool automatically asks you to enter one.

Extracting Files Without Directory Structure

We can also extract files from a RAR archive without preserving the original directory structure within the archive. This is useful when we want to remove the complexity of folder structure and need the files themselves. This in turn helps us to access the files quickly without entering the different directory levels. We can extract files without the directory structure using the 'e' option with the unrar command.

unrar e example.rar

The above command ignores the folders and subdirectories in the RAR archive and puts all the files together in the current working directory.

Advanced Unrar extraction options

Here is a table with some of the advanced useful options to extract files from unrar.

Option

Description

Example

r

Repair a damaged RAR file

unrar r example.rar

p

Print the contents of a file in RAR archive to standard output

unrar p example.rar file1.txt

v

Display detailed information about the archive

unrar v example.rar

c-

Disable display of comments during extraction

unrar -c- example.rar

cfg-

Turn off reading configuration

unrar -cfg- example.rar

idq

Turn off done messages indicating the completion of extraction

unrar -idq example.rar

inul

Disable all messages

unrar -inul example.rar

kb

Retain any partially extracted files if the extraction fails

unrar -kb example.rar

o+

Overwrite existing files

unrar -o+ example.rar

o-

Never overwrite existing files

unrar -o- example.rar

Extracting RAR Files Using GUI Methods

For user who prefer Graphical Interfaces (GUI), Linux offers many archive managers that can be used to manage RAR files. Some examples of these archive managers include (GNOME), Ark (KDE), and Xarchiver (XFCE). With simple 2-3 steps, users can easily extract RAR files. They just need to open the archive manager, find the RAR file, and choose "Extract" or "Extract to…" to extract the files.

Conclusion

Thus the unrar utility offers a number of options that can be used to manage and extract our RAR files in Linux. We can also refer to the unrar man page to get a complete list of unrar options.

What is Unrar in Linux?

Unrar is a utility tool in Linux that is used to extract files from RAR archives.

How can we extract files from a RAR archive?

We can use the command 'unrar x archive.rar' to extract files from a RAR archive to the current working directory. If the files have to be extracted to a specific directory, we just need to append the directory path with the previous unrar command at the end.

How do we view the contents of a file in a RAR archive without extracting it?

To view the contents of a file in a RAR archive we can use the 'p' option with unrar, 'unrar p file.rar'. This prints the contents of the file to the standard output.

What is the difference between the p and l options?

The 'p' option prints the contents of a specific file to the standard output, while the l option lists all contents of the RAR archive with additional details like name, size, ratio, date, time, version, etc.

Where can we find more details about Unrar options?

We can refer to the unrar manual page in Linux by using the 'man unrar' command for a complete list of options and details.



Next Article
Article Tags :

Similar Reads