RAR files are one of the most popular file compression formats, often used to pack multiple files into a single archive and compress them for easier storage or transfer. If you work on Linux, managing RAR files is quite straightforward with the right tools.

In this guide, we will walk you through how to extract and create RAR files in Linux systems.

Install rar and unrar

To handle RAR files on Linux, you need to install the rar and unrar utilities. Unfortunately, these aren’t included by default in many Linux distributions because RAR is proprietary software.

Install rar and unrar on Ubuntu/Debian:

apt update
apt install rar unrar

Install rar and unrar on Fedora/RHEL:

dnf install rar unrar

Once installed, you’re ready to start working with RAR files.

How to Extract RAR Files in Linux

To extract RAR files, you can use the unrar command. The syntax is simple, and you can specify the target directory if necessary.

Extracting a RAR File in the Current Directory

To extract the contents of a RAR file into the current directory, use the following command:

unrar x archive.rar

Extracting a RAR File to a Specific Directory

You can specify a directory to extract the contents to using the following command:

unrar x archive.rar /opt/

Extracting Password-Protected RAR Files

If your RAR file is password-protected, you can extract it by specifying the password when prompted:

unrar x archive.rar

How to Create RAR Files in Linux

To create RAR archives, you’ll use the rar command. Here’s how you can compress files into a RAR archive.

Creating a Simple RAR Archive

To create a RAR file from multiple files, run the following command:

rar a archive.rar file1.txt file2.pdf file3.jpg

Creating a RAR File with a Password

You can create a password-protected RAR file using the -p option:

rar a -p archive.rar file1.txt file2.pdf file3.jpg

Specifying Compression Levels

You can control the compression level when creating RAR files using the -m option followed by a number between 0 (no compression) and 5 (maximum compression):

rar a -m5 archive.rar file1.txt file2.pdf file3.jpg

Conclusion

This guide covered installing the rar and unrar utilities, extracting files from RAR archives, and creating new RAR files. We also explored on password protection and adjusting compression levels. You can easily manage RAR archives on your Linux system just as on Windows or macOS. Try practicing rar with all available options on VPS hosting from Atlantic.Net!