How to Open, Extract and Create RAR Files in Linux

Extract and Create RAR Files

In this tutorial, we will learn how to Extract and Create RAR Files with their different attributes. This tutorial can be used for both Ubuntu(18.04, 20.04) and CentOS(7, 8).

RAR is one of the most popular package for creating and extracting compressed archive (.rar) files. On the internet, normally files are uploaded in compressed form. To extract them we need to install the RAR package.

RAR package is an open-source package, anyone can install and use this package. RAR supports many operating systems such as Linux, Windows, etc. In many operating systems, the RAR package is not installed by default. We need to install the package manually.

Read Also: How to Install and Configure OwnCloud on CentOS 8

Install RAR in Linux

RAR package is useful when extracting compressed files. To install the RAR package, run the following command as per your operating system.

Ubuntu 18.04 / 20.04

  • Update the server.
apt update -y
  • Install the RAR package.
sudo apt-get install rar -y

CentOS 7 / 8

  • Install DNF package.
yum install dnf -y
  • Install Wget packages.
yum install wget -y
  • Download cert forensics tools package.
wget https://forensics.cert.org/cert-forensics-tools-release-el8.rpm
  • Install the cert forensics tools package on the server.
rpm -Uvh cert-forensics-tools-release*rpm
  • Install the RAR rpm package.
dnf --enablerepo=forensics install rar -y 

How to Create RAR File in Linux

To create an archive RAR file run the RAR command with a attribute

rar a file.rar directory

Replace file_name.rar with your RAR file name which you want to create then mentioned the path of directories.

How to Delete Archive or files from

To delete a specific file from a RAR file, run the following command.

rar d file.rar File_path

Replace the filename.rar with your RAR file name and then mentioned the path of the file which you want to delete from the archive(RAR file).

How to Set Password to Archives

It is one of the most interesting and useful features of RAR. You can protect the RAR file, by setting Password on the RAR file.

To set a password on the RAR file, run the RAR command with a and -p attribute,  it will create the password enable RAR file.

rar a -p File.rar /path/

To test that the password, simply hit the below command.

rar x Rar_file_name

How to Lock Archives

It is also an interesting and useful feature of the RAR. This feature allows you to set a lock on a particular archive file from extracting it.

rar k File_name.rar Path_of_the_file

Install Unrar in Linux

The Unrar command is used to extract the compressed files, list the files in an Archive file, Test the files. RAR command cannot be used to extract the RAR file, so we have to install the Unrar package.

To install the Unrar package run the following command.

Ubuntu 18.04 / 20.04

  • Update the server.
apt update -y
  • Install the Unrar Package.
sudo apt install unrar -y

CentOS 7 / 8

  • Install DNF package.
yum install dnf -y
  • Install Wget packages.
yum install wget -y
  • Download cert forensics tools package.
wget https://forensics.cert.org/cert-forensics-tools-release-el8.rpm
  • Install the cert forensics tools package on the server.
rpm -Uvh cert-forensics-tools-release*rpm
  • Install the Unrar package.
yum install unrar -y

How to Extract a RAR File

To extract the RAR file in the current working directory, simply run the following command Unrar with e attribute.

unrar e Rar_file_name

Replace Rar_file_name and enter the name of the RAR file which you want to extract.

If you want to extract the file at a specific path then use the Unrar command with e attribute then mentioned the path where you want to extract the file.

unrar e Rar_file_name.rar /path/

The above commands will only extract the files without creating the directory structure.

To Extract the RAR with the directory structure just run the Unrar with x attribute. This command will exactly create the same directory structure as in the RAR file.

unrar x tecmint.rar

How to List a RAR File

To list the files which are stored in an archive, simply run the Unrar command with the l attribute. It will show the list of the files with their permission, date, time, and size.

unrar l Rar_file_name.rar

How to Test a RAR File

To test the integrity of the RAR file run the Unrar command with t attribute. This command will perform a complete integrity test on each file and directory and then show the status.

unrar t Rar_file_name.rar

Conclusion

In this tutorial, we have learned how to install and use the Rar and Unrar commands. You can easily install it on Ubuntu (18.04, 20.04), CentOS (7,8). If you want detailed information about the Rar and Unrar, run the following command.

man unrar
man rar

If you guys have any problems or queries related to this Extract and Create RAR Files tutorial, then let me know in the comment section.