How to Open, Extract and Create RAR Files in Linux?

RAR is a popular file compression format known for its efficient compression algorithm and ability to compress large files into smaller archives. While Linux natively supports common archive formats like ZIP and TAR, working with RAR files requires additional tools. In this guide, we will explore how to open, extract, and create RAR files in Linux.

Whether you've received a RAR file and need to extract its contents or want to compress files into a RAR archive, we will cover the necessary steps and tools to accomplish these tasks. We will explore both command-line methods and advanced options, giving you the flexibility to choose the approach that suits your needs.

Installing the Required Tools

Before we can start working with RAR files in Linux, we need to ensure that we have the necessary tools installed. By default, Linux distributions do not include built-in support for RAR files. However, we can easily install the required software packages to enable RAR file management.

Installing the UnRAR Package

The UnRAR package provides the necessary tools to extract files from RAR archives. To install it, open your terminal and run the following command

sudo apt-get install unrar

Installing the RAR Package

If you also want the ability to create RAR archives, you'll need to install the RAR package. Use the following command to install it

sudo apt-get install rar

For other Linux distributions, use the appropriate package manager:

Distribution UnRAR Installation RAR Installation
CentOS/RHEL sudo yum install unrar sudo yum install rar
Fedora sudo dnf install unrar sudo dnf install rar
Arch Linux sudo pacman -S unrar sudo pacman -S rar

Opening and Extracting RAR Files

Once we have the necessary tools installed, we can easily open and extract RAR files in Linux. Follow these steps

Basic Extraction

Navigate to the directory containing your RAR file and use the unrar command:

cd ~/Downloads
unrar x archive.rar

Extract to Specific Directory

To extract files to a specific folder, provide the destination path:

unrar x archive.rar /path/to/destination/folder

Common UnRAR Options

Option Description Example
x Extract with full path unrar x archive.rar
e Extract files to current directory unrar e archive.rar
l List contents without extracting unrar l archive.rar
t Test archive integrity unrar t archive.rar

Creating RAR Files

In addition to extracting RAR files, you can also create your own RAR archives in Linux using the rar command.

Basic Archive Creation

To create a RAR archive, use the following syntax:

rar a myarchive.rar file1.txt file2.txt

Archive Entire Directory

To compress an entire directory:

rar a -r myarchive.rar /path/to/directory/

Compression Levels

You can specify compression levels from 0 (no compression) to 5 (maximum compression):

rar a -m5 myarchive.rar files/

Creating Password-Protected RAR Files

To enhance the security of your RAR archives, you can create password-protected RAR files. This ensures that only users with the correct password can access the contents of the archive.

Basic Password Protection

Use the -p option followed by the password:

rar a -p'mypassword' secure.rar document.txt

Interactive Password Prompt

For better security, use -hp to prompt for password without displaying it:

rar a -hp secure.rar document.txt

Extracting Password-Protected Archives

When extracting password-protected RAR files, you'll be prompted for the password:

unrar x secure.rar

Advanced RAR Options

Option Description Example
-v<size> Create multi-volume archives rar a -v100M archive.rar files/
-rr<%> Add recovery record rar a -rr5 archive.rar files/
-x<pattern> Exclude files matching pattern rar a -x*.tmp archive.rar files/
-df Delete files after archiving rar a -df archive.rar files/

Conclusion

Working with RAR files in Linux is made possible through the command-line tools unrar and rar. These utilities provide comprehensive functionality to extract existing archives and create new ones with various compression and security options. With the knowledge gained from this guide, you can efficiently manage RAR files in your Linux environment, whether for basic extraction or advanced archive creation with password protection and custom compression settings.

Updated on: 2026-03-17T09:01:39+05:30

899 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements