How To Create RAR Archive In Linux?


Like other archives, a RAR file is a data container that stores one or several files in compressed form. RAR is a proprietary file format which is developed by Eugene Roshal. It is a native file format for the WinRAR archiver.

RAR file uses .rar file extension. It is frequently used in Windows OS. If you have downloaded such a file then first you need to extract the RAR file with an application that supports RAR file format and then you can use it. WinRAR application is officially not available for Linux but we can use some other applications to create or extract a RAR file.

But, ahead in this article, we will discuss how to create a RAR file in Linux. Opening and extracting of RAR file will be covered in separately.

How to Install rar command in Lunux?

We will use the rar command for archiving files with compression in the RAR file format. So first we need to install it in our system, Use the following command to install it-

Debian Based Ubuntu, Linux Mint etc:

If you are using a Debian based distribution such as Ubuntu, Linux Mint, etc. then use –

sudo apt install rar

Or

sudo apt-get install rar

RPM-based Cent OS, RedHat Linux etc:

Or if you are using an rpm-based Linux distribution such as centos, Redhat, etc then use –

sudo yum install rar

For Fedora:

To install rar in Fedora, use –

sudo dnf install rar

Once the installation gets completed you can use the rar command to create rar files.

How to Create a RAR file in Linux?

To create a rar file we will have to use rar command with the option a in the terminal. Suppose I have a directory named sample which contains some files in it. Now to create sample.rar we will use the following command in our terminal –

rar a sample.rar sample

Once you execute this command you will see output something like given in the below image –

This will create a file named sample.rar inside the same directory.

Update a RAR file

To update or add a file to an existing rar file you need to use u option with rar command. Now execute the following command in your terminal. here we are going to add abc file to sample.tar –

rar u sample.tar abc

Display the list of files and directories inside a rar file

To display the list of files and directories within a rar file use the option l with the rar command –

rar l sample.rar

Deleting a RAR file

Now if you want to delete a rar file then you can use the following command in your terminal this will delete every file of inside it –

rar d filename.rar

Conclusion

The rar program provides a lot more options that you can use with the rar command. You can check them in the manual page of the rar. Execute the following command to see manual page-

man rar

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.