How to Unrar Files in Linux
Last Updated :
21 Jun, 2024
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

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

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 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/'.

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.

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.
Similar Reads
How to Delete Files in Linux?
Linux comes with several tools that can assist us in removing Directories and files. We always need to delete many files and folders based on a set of requirements. To complete our mission quickly, knowing a few basic commands and their variations is beneficial. Use caution when using the commands b
6 min read
How to Run a File in Linux
The command line is one of the most powerful tools in Linux. It allows you to execute commands, manage files, and automate tasks all from a single terminal window. One common task you'll often need to do is run a file, whether itâs a script, a compiled program, or even a text file. In this article,
6 min read
How to Open a File in Linuxâ
In Linux, a file is a fundamental unit of storage, representing everything from documents and images to system logs and program data. Unlike traditional operating systems, Linux treats almost everythingâfiles, directories, devices, and processesâas a file. Whether you're accessing a simple text docu
6 min read
How to Create File in Linux
Today, we're going to learn about something really important â how to create files in Linux. It's like creating a fresh piece of digital paper to write or store things. We'll explore different ways to do this using simple commands. Whether you're just starting out or have been using Linux for a bit,
7 min read
How to open ISO files on Ubuntu Linux
ISO files are disc image archives commonly used to distribute software and operating systems. There are two main ways to access the contents of an ISO file on Ubuntu Linux: using the graphical user interface (GUI) or the command line. What is an ISO File?An ISO file or an ISO image is a single data
5 min read
How to Unpack a PKL File in Python
Unpacking a PKL file in Python is a straightforward process using the pickle module. It allows you to easily save and load complex Python objects, making it a useful tool for many applications, especially in data science and machine learning. However, always be cautious about the security implicatio
3 min read
How to Find Out File Types in Linux
In Linux, everything is considered as a file. In UNIX, seven standard file types are regular, directory, symbolic link, FIFO special, block special, character special, and socket. In Linux/UNIX, we have to deal with different file types to manage them efficiently.Categories of Files in Linux/UNIXIn
7 min read
How to Unstage a File in Git?
Git is a powerful version control system widely used for tracking changes in source code during software development. One common operation in Git is staging files, preparing them for a commit. However, there are times when you may need to unstage a file before committing your changes. This article w
2 min read
How to Compress Files in Linux | Tar Command
File compression is a fundamental task in managing and transferring data efficiently on a Linux system. The Tar command, short for Tape Archive, is a powerful tool that allows users to create compressed and archived files. In this comprehensive guide, we will explore the various options and examples
11 min read
How to Move File in Linux | mv Command
The `mv` command in Linux is like a superhero tool that can do a bunch of cool stuff with your files and folders. Think of it as a digital moving truck that helps you shift things around in your computer. Whether you want to tidy up your folders, give your files new names, or send them to different
7 min read