How to Open, Extract and Create RAR Files in Linux

RAR is the most popular tool for creating and extracting compressed archive (.rar) files. When we download an archive file from the web, we required a rar tool to extract them.

RAR is available freely under Windows operating systems to handle compressed files, but unfortunately, the rar tool doesn’t pre-installed under Linux systems.

This article explains how to install unrar and rar command-line tools using official binary tar files under Linux systems to open, extract, uncompress, or unrar an archive file.

Step 1: How to Install Unrar on Linux

On Debian and Ubuntu-based distributions, you can easily install unrar package using the apt-get or apt program as shown.

$ sudo apt-get install unrar
Or
$ sudo apt install unrar

If you are using RHEL-based distributions, you can use the dnf command or yum command to install it.

------------ 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 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-621.tar.gz
# tar -zxvf rarlinux-x64-621.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-621.tar.gz
# tar -zxvf rarlinux-x32-621.tar.gz
# cd rar
# sudo cp -v rar unrar /usr/local/bin/

Step 2: How to Open/Extract a RAR File in Linux

To open/extract a RAR file in the current working directory, just use the following command with the unrar e option.

# unrar e tecmint.rar

UNRAR 4.20 beta 3 freeware      Copyright (c) 1993-2012 Alexander Roshal

Extracting from tecmint.rar

Extracting  index.php                                                 OK
Extracting  index.html                                                OK
Extracting  xyz.txt                                                   OK
Extracting  abc.txt                                                   OK
All OK

To open/extract a RAR file in a specific path or destination directory, just use the unrar e option, it will extract all the files in the specified destination directory.

# unrar e tecmint.rar /home/

UNRAR 4.20 beta 3 freeware      Copyright (c) 1993-2012 Alexander Roshal

Extracting from tecmint.rar

Extracting  /home/index.php                                           OK
Extracting  /home/index.html                                          OK
Extracting  /home/xyz.txt                                             OK
Extracting  /home/abc.txt                                             OK
All OK

To open/extract a RAR file with its original directory structure, just issue the below command with the unrar x option. It will extract according to their folder structure see below the output of the command.

# unrar x tecmint.rar

UNRAR 4.20 beta 3 freeware      Copyright (c) 1993-2012 Alexander Roshal

Extracting from tecmint.rar

Creating    tecmint                                                   OK
Extracting  tecmint/index.php                                         OK
Extracting  tecmint/index.html                                        OK
Extracting  tecmint/xyz.txt                                           OK
Extracting  tecmint/abc.txt                                           OK
Creating    default                                                   OK
Extracting  default/index.php                                         OK
Extracting  default/index.html                                        OK
Creating    include                                                   OK
Extracting  include/abc.txt                                           OK
Creating    php                                                       OK
Extracting  php/xyz.txt                                               OK
All OK

Step 3: How to List a RAR File in Linux

To list files inside an archive file use the unrar l option. It will display the list of files with their sizes, date, time, and permissions.

unrar l tecmint.rar

UNRAR 4.20 beta 3 freeware      Copyright (c) 1993-2012 Alexander Roshal

Archive tecmint.rar

 Name             Size   Packed Ratio  Date   Time     Attr      CRC   Meth Ver
-------------------------------------------------------------------------------
 index.php           0        8   0% 18-08-12 19:11 -rw-r--r-- 00000000 m3b 2.9
 index.html          0        8   0% 18-08-12 19:11 -rw-r--r-- 00000000 m3b 2.9
 xyz.txt             0        8   0% 18-08-12 19:11 -rw-r--r-- 00000000 m3b 2.9
 abc.txt             0        8   0% 18-08-12 19:11 -rw-r--r-- 00000000 m3b 2.9
 index.php           0        8   0% 18-08-12 19:22 -rw-r--r-- 00000000 m3b 2.9
 index.html          0        8   0% 18-08-12 19:22 -rw-r--r-- 00000000 m3b 2.9
 abc.txt             0        8   0% 18-08-12 19:22 -rw-r--r-- 00000000 m3b 2.9
 xyz.txt             0        8   0% 18-08-12 19:22 -rw-r--r-- 00000000 m3b 2.9
-------------------------------------------------------------------------------
    8                0       64   0%

Step 4: How to Test a RAR File in Linux

To test the integrity of an archive file, use option unrar t. The below command will perform a complete integrity check for each file and displays the status of the file.

unrar t tecmint.rar

UNRAR 4.20 beta 3 freeware      Copyright (c) 1993-2012 Alexander Roshal

Testing archive tecmint.rar

Testing     tecmint/index.php                                         OK
Testing     tecmint/index.html                                        OK
Testing     tecmint/xyz.txt                                           OK
Testing     tecmint/abc.txt                                           OK
Testing     default/index.php                                         OK
Testing     default/index.html                                        OK
Testing     include/abc.txt                                           OK
Testing     php/xyz.txt                                               OK
All OK

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 RAR command-line utility to create archive files.

Step 5: How to Install Rar in Linux

To install the RAR command option in Linux, just execute the following command.

$ 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]    

Sample Output:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Dependencies Resolved
=========================================================================================
 Package			Arch			Version				Repository			Size
=========================================================================================
Installing:
 rar				i386            3.8.0-1.el5.rf      rpmforge			264 k

Transaction Summary
=========================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 264 k
Is this ok [y/N]: y
Downloading Packages:
rar-3.8.0-1.el5.rf.i386.rpm										| 264 kB     00:01
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : rar                                          1/1

Installed:
  rar.i386 0:3.8.0-1.el5.rf

Complete!

Step 6: How to Create Rar File in Linux

To create an archive (RAR) file in Linux, run the following command with rar a option. It will create an archive file for a tecmint directory.

rar a tecmint.rar tecmint

RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help

Evaluation copy. Please register.

Creating archive tecmint.rar

Adding    tecmint/index.php                                           OK
Adding    tecmint/index.html                                          OK
Adding    tecmint/xyz.txt                                             OK
Adding    tecmint/abc.txt                                             OK
Adding    tecmint                                                     OK
Done

Step 7: How to Delete Files from the Archive

To delete a file from an archive file, run the command.

rar d filename.rar

Step 8: How to Recover Archives

To recover or fix an archive file or files, run the command with option rar r.

rar r filename.rar

RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help

Building fixed.tecmint.rar
Scanning...
Data recovery record not found
Reconstructing tecmint.rar
Building rebuilt.tecmint.rar
Found  tecmint\index.php
Found  tecmint\index.html
Found  tecmint\xyz.txt
Found  tecmint\abc.txt
Found  tecmint
Done

Step 9: How to Update Archives

To update or add files to the existing archive file, use the following command with the option rar u.

rar u tecmint.rar tecmint.sql

RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help

Evaluation copy. Please register.

Updating archive tecmint.rar

Adding    tecmint.sql                                                 OK
Done

Now, verify that the file tecmint.sql is added to the archive file.

rar l tecmint.rar

RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help

Archive tecmint.rar

 Name             Size   Packed Ratio  Date   Time     Attr      CRC   Meth Ver
-------------------------------------------------------------------------------
 index.php           0        8   0% 18-08-12 19:11 -rw-r--r-- 00000000 m3b 2.9
 index.html          0        8   0% 18-08-12 19:11 -rw-r--r-- 00000000 m3b 2.9
 xyz.txt             0        8   0% 18-08-12 19:11 -rw-r--r-- 00000000 m3b 2.9
 abc.txt             0        8   0% 18-08-12 19:11 -rw-r--r-- 00000000 m3b 2.9
 tecmint             0        0   0% 18-08-12 19:23 drwxr-xr-x 00000000 m0  2.0
 tecmint.sql 0 8 0% 18-08-12 19:46 -rw-r--r-- 00000000 m3b 2.9
-------------------------------------------------------------------------------
    6                0       40   0%

Step 10: How to Set Password to Archives

This is a very interesting feature of the Rar tool, it allows us to set a password to the archive files. To password-protect archive files use option rar a -p.

rar a -p tecmint.rar

Enter password (will not be echoed):

Reenter password:

AR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help

Evaluation copy. Please register.

Updating archive tecmint.rar

Updating  tecmint.sql                                                 OK
Done

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

RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help

Extracting from tecmint.rar

Creating    tecmint                                                   OK
Extracting  tecmint/index.php                                         OK
Extracting  tecmint/index.html                                        OK
Extracting  tecmint/xyz.txt                                           OK
Extracting  tecmint/abc.txt                                           OK
Enter a password (will not be echoed) for tecmint.sql:

Extracting  tecmint.sql                                               OK
All OK

Step 11: How to Lock Archives

Another interesting lock feature of the rar tool, it provides an option to lock a particular archive file after extracting it.

rar k tecmint.rar

RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help

Processing archive tecmint.rar
Locking archive
Done

Conclusion

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.

If you read this far, tweet to the author to show them you care. Tweet a thanks
Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

24 thoughts on “How to Open, Extract and Create RAR Files in Linux”

  1. Does nobody use WinRAR? I wouldn’t touch 7zip if nothing else was available out there. I can still easily add additional files to WinRAR archives, whereas with 7zip I can’t. I have to unzip the archive, then add additional files and then zip it all up again.

    Reply
  2. How to unrar a .rar file without listing all the filenames but just the percentage status of extracting?

    This code that I run:

    !unrar x Concrete-Crack-Images-for-Classification.rar @
    

    is not enough. It does not show the percentage status of extracting.

    Reply
    • @Fadie,

      The simple way to open a rar file in Linux, use:

      # unrar e tecmint.rar
      

      And those 10 commands are examples to play with rar files in Linux..

      Reply
  3. i have installed backtrack5r3 on vmware. Now i want to extract a rar file present on desktop but i can’t do it.plz help me.
    i had used the following command.
    unrar e video.rar

    Reply

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.