RAR is the most popular tool for creating and extracting compressed archive
(.rar) files. When we download an archive file from the web, we require a rar tool to extract them.
RAR is available freely under Windows operating systems to handle compressed files, but unfortunately, the rar tool isn’t pre-installed under Linux systems.
In this article, we’ll guide you through the process of installing unrar and rar command-line tools to open, extract, uncompress, or unrar and create an archive file on a Linux system.
Table of Contents
Install Unrar on Linux
To work with RAR files on Linux, you’ll need the unrar tool, which allows you to extract content from RAR archives. To install unrar, open a terminal and use the default package manager specific to your Linux distribution.
$ sudo apt-get install unrar Or $ sudo apt install unrar
------------ On Fedora Linux ------------ $ sudo dnf install unrar ------------ On RHEL-based Linux ------------ $ sudo yum install epel-release $ sudo yum install unrar
On other popular Linux distributions, you can install it using your default package manager as shown.
$ sudo emerge -a app-arch/unrar [On Gentoo Linux] $ sudo apk add unrar [On Alpine Linux] $ sudo pacman -S unrar [On Arch Linux] $ sudo zypper install unrar [On OpenSUSE]
If your distribution does not offer an unrar package, you need to download the latest unrar/rar file and install it using the following commands.
--------------- On 64-bit --------------- # cd /tmp # wget https://www.rarlab.com/rar/rarlinux-x64-623.tar.gz # tar -zxvf rarlinux-x64-623.tar.gz # cd rar # sudo cp -v rar unrar /usr/local/bin/ --------------- On 32-bit --------------- # cd /tmp # wget https://www.rarlab.com/rar/rarlinux-x32-623.tar.gz # tar -zxvf rarlinux-x32-623.tar.gz # cd rar # sudo cp -v rar unrar /usr/local/bin/
How to Extract RAR Files in Linux
Once you have unrar installed, you can easily open or extract the contents of a RAR file in the current working directory by using the following command with the
$ unrar e tecmint.rar
To open/extract a RAR file in a specific path or destination directory, just use the
e option, it will extract all the files in the specified destination directory.
$ unrar e tecmint.rar /home/tecmint/rarfiles
To open/extract an RAR file with its original directory structure, just issue the below command with the
x option, which will extract according to their folder structure see below the output of the command.
$ unrar x tecmint.rar
How to List RAR Files in Linux
To list the contents of an RAR file in Linux, you can use the
unrar l command, which will display the list of files with their sizes, dates, time, and permissions.
$ unrar l tecmint.rar
How to Check Integrity of RAR File in Linux
To check the integrity of an RAR archive file, you can use the
unrar t command, which will perform a complete integrity check for each file for errors and displays the status of the file.
$ unrar t tecmint.rar
The unrar command is used to extract, list, or test archive files only. It has no option for creating RAR files under Linux. So, here we need to install the RAR command-line utility to create archive files.
How to Install Rar in Linux
The rar command-line utility is used to create RAR archives, you can install rar using a package manager appropriate for your Linux distribution,
$ sudo apt install rar [On Debian, Ubuntu and Mint] $ sudo yum install rar [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a app-arch/rar [On Gentoo Linux] $ sudo apk add rar [On Alpine Linux] $ sudo pacman -S rar [On Arch Linux] $ sudo zypper install rar [On OpenSUSE]
How to Create RAR File in Linux
To create an archive (RAR) file in Linux, run the following command with
a option, which will create an archive file for a tecmint directory.
$ rar a tecmint.rar tecmint
How to Delete Files in RAR Archive
rar d command is used to delete files from an existing RAR archive in Linux. The
d option directly modifies the existing RAR archive by removing the specified files.
$ rar d tecmint.rar randfile001 randfile002
In the above command, the randfile001 and randfile002 files will be deleted from the tecmint.rar RAR archive.
How to Repair RAR Files in Linux
rar r command is used to repair and recover data from damaged or corrupted RAR archives in Linux.
$ rar r tecmint.rar
How to Add Files to RAR Archive
To update or add files to the existing archive file, use the
rar u command, which allows you to add files to an existing RAR archive or update files within the archive.
$ rar u tecmint.rar hello.py
Now, verify that the file tecmint.sql is added to the archive file.
$ rar l tecmint.rar
How to Set Password to RAR File
This is a very interesting feature of the rar tool, which allows us to set a password to the RAR archive file using the following command.
$ rar a -p tecmint.rar
Now verify it by extracting the archive file and see whether it will prompt us to enter the password that we have set above.
$ rar x tecmint.rar
How to Lock RAR File
rar k command is used to lock an existing RAR archive file, which is useful if you want to prevent further modifications to the archive.
$ rar k tecmint.rar
For more RAR and Unrar options and usage, run the following command it will display a list of options with their description.
$ man unrar $ man rar
We have presented almost all of the options above for rar and unrar commands with their examples. If you feel that we’ve missed anything in this list and you would like us to add, please update us using the comment form below.