How to Create, Extract and Open RAR files in Linux

To Create, Extract and Open RAR files in Linux

This article explains how to create, extract and open RAR files using RPMforge repository under Linux systems. RAR is tool to create and extract compressed archieve (.rar) files.


To Enable RPMForge Repository

RPMForge repository is by default available, so Fedora users need not install it again.

RHEL/CentOS 6 64-Bit

[root@linuxhelp Desktop]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
--2016-03-15 19:18:17-- http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm Resolving pkgs.repoforge.org... 78.46.17.228 ... ... ... Saving to: “ rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm”  100%[======================================> ] 12,700 11.8K/s in 1.1s 2016-03-15 19:18:24 (11.8 KB/s) - “ rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm”  saved [12700/12700] [root@linuxhelp Desktop]# rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm Preparing... ########################################### [100%] 1:rpmforge-release ########################################### [100%]


To Install Unrar in Linux

[root@linuxhelp Desktop]# yum install unrar
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
....
....
....
 Installed:
  unrar.i386 0:4.2.3-1.el5.rf

Complete!


To Open/Extract a RAR File

The following command with unrar e option is used to Open/Extract a RAR File in Linux.

[root@linuxhelp Desktop]# unrar e test.rar
UNRAR 5.00 beta 3 freeware      Copyright (c) 1993-2013 Alexander Roshal

Extracting from test.rar

Extracting  test1                                                    OK
Extracting  test2                                                    OK
Extracting  test3                                                    OK
All OK


To open/extract a RAR file in specific path or destination directory

The unrar e option is used to extract all the files in specified destination directory.

[root@linuxhelp Desktop]# unrar e test.rar /root/Desktop/new/

UNRAR 5.00 beta 3 freeware      Copyright (c) 1993-2013 Alexander Roshal

Extracting from test.rar

Extracting  /root/Desktop/new/test1                                  OK
Extracting  /root/Desktop/new/test2                                  OK
Extracting  /root/Desktop/new/test3                                  OK
All OK

[root@linuxhelp Desktop]# cd new
[root@linuxhelp new]# ll
total 12
-rw-r--r-- 1 root root 20 Mar 15 20:19 test1
-rw-r--r-- 1 root root 13 Mar 15 20:20 test2
-rw-r--r-- 1 root root 20 Mar 15 20:20 test3


To open/extract a RAR file with their original directory structure

The unrar x option is used to extract according their folder structure.

[root@linuxhelp Desktop]# unrar x test.rar

UNRAR 5.00 beta 3 freeware      Copyright (c) 1993-2013 Alexander Roshal

Extracting from test.rar
Extracting  test1                                                    OK
Extracting  test2                                                    OK
Extracting  test3                                                    OK
Creating    test                                                      OK
All OK


To List a RAR File in Linux

Use unrar l option to display the list of files with their sizes, date, time and permissions.

[root@linuxhelp Desktop]# unrar l test.rar

UNRAR 5.00 beta 3 freeware      Copyright (c) 1993-2013 Alexander Roshal

Archive: test.rar
Details: RAR 4

 Attributes      Size    Date   Time   Name
----------- ---------  -------- -----  ----
 -rw-r--r--        20  15-03-16 20:19  test1      
 -rw-r--r--        13  15-03-16 20:20  test2      
 -rw-r--r--        20  15-03-16 20:20  test3      
 drwxr-xr-x         0  15-03-16 20:20  test        
----------- ---------  -------- -----  ----
                   53                  4


To Test a RAR File in Linux

Option unrar t is used to perform a complete integrity check for each file and displays the status of the file.

[root@linuxhelp Desktop]# unrar t test.rar

UNRAR 5.00 beta 3 freeware      Copyright (c) 1993-2013 Alexander Roshal
Testing archive test.rar
Testing     test1                                                    OK
Testing     test2                                                    OK
Testing     test3                                                    OK
Testing     test                                                      OK
All OK


To Install rar in Linux

[root@linuxhelp Desktop]# yum install rar
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
...
...
...
Installed:
  rar.x86_64 0:3.8.0-1.el6.rf                                                   

Complete!


To Create rar File in Linux

rar a option is used to create archive file for test directory.

[root@linuxhelp Desktop]# rar a test.rar test

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

Evaluation copy. Please register.

Creating archive test.rar

Adding    test/1                                                      OK
Adding    test/2                                                      OK
Adding    test/3                                                      OK
Adding    test                                                        OK
Done

To Delete files from Archive

Run the following command to delete a archive file.

[root@linuxhelp Desktop]# rar d test.rar

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

Deleting from test.rar
Deleting test/1
Deleting test/2
Deleting test/3
Deleting test
Erasing empty archive test.rar
Done


To Recover Archives

Option rar r is used to recover or fix a archive file or files

[root@linuxhelp Desktop]# rar r test.rar

RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help
Building fixed.test.rar
Scanning...
Data recovery record not found
Reconstructing test.rar
Building rebuilt.test.rar
Found  test1
Found  test2
Found  test3
Found  test
Done


To Update Archives

Option rar u is used to update or add files to existing archive file

[root@linuxhelp Desktop]# rar u test.rar file
RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help
Evaluation copy. Please register.
Updating archive test.rar

Adding    file                                                        OK
Done

check if file is added to archive

[root@linuxhelp Desktop]# rar l test.rar

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

Archive test.rar

 Name             Size   Packed Ratio  Date   Time     Attr      CRC   Meth Ver
-------------------------------------------------------------------------------
 1                  50       58 116% 15-03-16 19:36 -rw-r--r-- E080B7A9 m3b 2.9
 2                  31       40 129% 15-03-16 19:37 -rw-r--r-- DE74BA1E m3b 2.9
 3                  20       34 170% 15-03-16 19:38 -rw-r--r-- F8D4F4D5 m3b 2.9
 test                0        0   0% 15-03-16 19:38 drwxr-xr-x 00000000 m0  2.0
 file               50       58 116% 15-03-16 19:36 -rw-r--r-- E080B7A9 m3b 2.9
-------------------------------------------------------------------------------
    5              151      190 125%


To Set Password to Archives

Option rar a -p is used to set a password to archive file

[root@linuxhelp Desktop]# rar a -p test.rar

Enter password (will not be echoed):

Reenter password:

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

Evaluation copy. Please register.

Updating archive test.rar

Updating  file                                                        OK
Adding    download_link                                               OK
Adding    rebuilt.test.rar                                            OK
Adding    rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm                  OK
Done

enter the password which is set above

[root@linuxhelp Desktop]# rar x test.rar

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

Extracting from test.rar

Extracting  test/1                                                    OK
Extracting  test/2                                                    OK
Extracting  test/3                                                    OK
Enter password (will not be echoed) for file:
Extracting  download_link                                          OK
Extracting  rebuilt.test.rar                                          OK

All OK


To Lock Archives

[root@linuxhelp Desktop]# rar k test.rar

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

Processing archive test.rar
Locking archive
Done


To display a list of options with their description

[root@linuxhelp Desktop]# man unrar
[root@linuxhelp Desktop]# man rar

FAQ
Q
How to protect a rar file in Linux server?
A
Protect the file by giving the password for the file using the following command

#rar a -p "filename"
Q
How to add new file to an existing rar file in Linux?
A
You can add the new files using the following command

# rar u "new file" "existing rar file"
Q
Is there any option to recover the deleted archive files?
A
yes, Use the following command to recover the deleted archive file

# rar a “filename.rar”
Q
How to list the content of .rar files in Linux?
A
you can list the content by using the following command

# unrar 1 "rarfilename.rar"
Q
What is the package to install for extracting the rar file in Linux?
A
For Debian based distro’s:

# apt-get install rar

For Red Hat based distro’s:

# yum install rar