If you experience any difficulty in accessing content on our website, please contact us at 1-866-333-8917 or email us at support@chicagovps.net and we will make every effort to assist you.

By
September 18, 2024

Mastering RAR Files on Linux: A Guide to Creating and Extracting Archives

 

RAR files are widely used on Windows, providing an efficient way to handle large file sizes and facilitating the sharing of files across different platforms. Although TAR files are predominantly used on Linux, managing RAR files is equally straightforward. However, suppose you need to extract or share a RAR file with a Windows user directly from the Linux terminal. In that case, this article will guide you through the process of creating and extracting RAR files using the unrar command on Linux.

We will discuss how to work with RAR files on Linux, which requires two essential utilities: rar and unrar. The installation of these tools is straightforward but varies depending on your Linux distribution.

For users of Debian-based distributions such as Ubuntu and its derivatives, you can easily install both utilities by executing the following commands:

For Arch Linux, run:

If you’re using Red Hat-based distribution (RHEL, CentOS, Fedora), first set up EPEL repository, then use:

Alternatively, if you prefer building RAR from the source code, download its TAR files from the official RAR website. After the installation is finished, you’ll be all set to begin creating and working with RAR files on your Linux system.

To create a RAR file, first, you require some files or directories that can be compressed and archived. For the demonstration, let’s take some sample text files.

First, create the text files using the touch command:

Next, you can add these files to a RAR archive by following rar command:

One thing to note here is the use of the a flag. It will add all the files or directories to the archive using the rar command. Next, you can specify the RAR file name followed by the list of all the files you want to archive in a RAR file.

Afterward, you can use the ls command to display the contents of the current directory, which will help verify whether the RAR file was successfully created:

To unpack a RAR file on a Linux system, you can utilize the unrar command along with the e parameter. This parameter instructs the unrar command to extract the contents of the archive file into the working directory.

Proceed with using the unrar command to decompress the previously mentioned RAR file:

If you prefer to direct the extracted files from a RAR archive to a designated folder rather than the default current directory, you can adjust the unrar command as follows:

In this adjusted command, the -d parameter specifies the target directory. You also have the option to alter the location for the extracted output file.

Note: Ensure the target directory exists before attempting to extract the RAR file; otherwise, the extraction command will fail.

Using the unrar command to extract files will result in a flattened list of files if you use the default e option, which doesn’t show the hierarchical directory structure in the terminal. To maintain the directory structure in your output, opt for the x option instead.

For an extraction that displays each file within its respective directory in the terminal, you can use:

This method allows the terminal to present a clearer view of the file organization within the archive.

Sometimes, you may receive RAR files from sources you don’t fully trust and wish to verify their safety before opening them. To do this without extracting the files, you can utilize the listing capability of the unrar command.

With the l option, it’s possible to explore the structure and details of the RAR file. For example, to check the contents of a test.rar file, you would use the command:

This command shows comprehensive data such as file sizes, permissions, creation dates and times, and the overall count of files in the archive.

When distributing a RAR file, it’s crucial to protect any confidential data from unwarranted exposure. To safeguard your files, you can either encrypt them with a password or lock the file to inhibit alterations.

RAR files usually apply AES-256 encryption when secured with a password, establishing a strong encryption model. Moreover, AES-256 is extremely secure, making it challenging to breach without the appropriate password.

To initiate a password, execute:

Following this, anyone needing to open your archive will require the password.

Beyond password security, you can prevent modifications to the RAR file by locking it. Implement the k command for this purpose:

Securing a RAR file from modifications is possible by locking it, though this does not prevent the file from being accessed or extracted. For complete restriction of access, employing password protection is essential. Locking the file merely ensures that the contents cannot be changed.

Utilizing the rar and unrar commands allows for comprehensive management of files whether you are extracting or creating archives that are secure and password-protected. Additionally, there are online tools to help extract RAR files.

Subscribe to receive our latest tutorials directly to your inbox.

Haroon is a lifelong tech enthusiast with over five years of experience writing thousands of articles about Linux, programming languages, and more. He loves exploring new technologies and experimenting with them to find innovative ways to use them. Haroon’s work has been featured on various online platforms, including HTG, Baeldung, and LinuxHint.

How to Extract Images From a PowerPoint or Google Slides Presentation

5 Ways to Extract and Copy Text From an Image on iPhone

10 Ways to Compress PDF Documents on Desktop and Mobile

How to Compress and Extract Files on Android Using ZArchiver

How to Compress a Video on Android

Affiliate Disclosure: Make Tech Easier may earn commission on products purchased through our links, which supports the work we do for our readers.


ChicagoVPS is your gateway to unparalleled hosting solutions. Our state-of-the-art datacenters and powerful network ensures lightning-fast speeds and uninterrupted connectivity for your websites and applications. Whether you’re a startup looking for scalable resources or an enterprise in need of enterprise-grade hosting, our range of plans and customizable solutions guarantee a perfect fit. Trust in ChicagoVPS to deliver excellence, combining unmatched reliability and top-tier support.

For Inquiries or to receive a personalized quote, please reach out to us through our contact form here or email us at sales@chicagovps.net.

Subscribe Email

Top