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 blog post, 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 and graphical methods, giving you the flexibility to choose the approach that suits your preference.

By the end of this guide, you'll have the knowledge and tools to effortlessly work with RAR files in your Linux environment. So, let's dive in and unlock the world of RAR file management on Linux.

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

Once the installation is complete, we can proceed to the next steps of opening and extracting RAR files, as well as creating our own RAR archives.

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 −

  • Open Terminal  Launch the terminal application on your Linux system.

  • Navigate to the Directory  Use the cd command to navigate to the directory where the RAR file is located. For example, if the RAR file is in the Downloads folder, use the following command:

cd ~/Downloads
  • Extract the RAR File  To extract the contents of the RAR file, use the unrar command followed by the name of the RAR file. For example, if the RAR file is named "archive.rar," use the following command:

unrar x archive.rar
  • Specify Destination Folder (Optional)  By default, the extracted files will be placed in the current directory. If you want to extract the files to a specific folder, provide the path after the RAR file name. For example:

unrar x archive.rar /path/to/destination/folder
  • Wait for Extraction  The unrar command will extract the contents of the RAR file to the specified location. Depending on the size of the RAR file and the system's performance, this process may take a few moments.

Once the extraction is complete, you can navigate to the destination folder to access the extracted files.

Creating RAR Files

In addition to extracting RAR files, you can also create your own RAR archives in Linux. Follow these steps:

  • Open Terminal  Launch the terminal application on your Linux system.

  • Navigate to the Directory  Use the cd command to navigate to the directory where the files you want to compress into a RAR archive are located. For example, if the files are in the Documents folder, use the following command:

cd ~/Documents
  • Create the RAR File  To create a RAR archive, use the rar command followed by the desired archive name and the files or directories you want to include in the archive. For example, to create a RAR archive named "myarchive.rar" containing two files named "file1.txt" and "file2.txt," use the following command:

rar a myarchive.rar file1.txt file2.txt
  • Compression Options (Optional)  You can specify additional compression options with the rar command. For example, you can set a password, adjust compression level, or exclude specific file types. Refer to the rar command's documentation for more details.

  • Wait for Compression  The rar command will create the RAR archive in the current directory. Depending on the size of the files and the system's performance, this process may take a few moments.

Once the compression is complete, you will have a RAR archive containing the specified files in the current directory.

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. Follow these steps 

  • Open Terminal  Launch the terminal application on your Linux system.

  • Navigate to the Directory  Use the cd command to navigate to the directory where the files you want to compress into a password-protected RAR archive are located.

  • Create the Password-Protected RAR File  To create a password-protected RAR archive, use the rar command with the -p option followed by the desired archive name, password, and the files or directories you want to include in the archive. For example, to create a password-protected RAR archive named "secure.rar" containing the file "document.txt" with the password "mypassword," use the following command:

rar a -p'mypassword' secure.rar document.txt
  • Compression Options (Optional)  Similar to creating regular RAR files, you can specify additional compression options with the rar command for password-protected archives.

  • Wait for Compression − The rar command will create the password-protected RAR archive in the current directory. It may take some time depending on the file sizes and system performance.

Once the compression is complete, you will have a password-protected RAR archive that requires the correct password to access its contents. Make sure to remember the password or keep it secure.

Conclusion

Working with RAR files in Linux is made possible through the use of command-line tools like unrar and rar. These utilities provide the ability to open, extract, and create RAR archives, allowing you to efficiently manage your files. By following the steps outlined in this guide, you can handle RAR files seamlessly, whether you need to extract the contents of an existing archive or create a password-protected RAR file for enhanced security.

Updated on: 09-Aug-2023

285 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements