How to extract or create rar file in Ubuntu/Linux

How to Extract or Create RAR file in Linux OS

RAR is a format of compressed file which is used to compressed files in archive format. Sometime we have rar files downloaded from internet then there is a need to extract all files from that rar file. The command used to extract these files is called “unrar”. By default, unrar is not being installed on Linux, Ubuntu like operating system we had to install it manually. It’s free for windows so by default comes with windows installation.

So here we will guide you to install rar/unrar in linux which will help in compressing or uncompressing file in .rar format.

As this is not by default with Operating system we have to install it manually using yum/apt-get or by source.

if you would like to install this application using yum then need to add repository if not added already. so below steps will install rpmforge repository in your system.

RHEL/Centos 32 Bit

########## RHEL/CentOS 6 32-Bit ############
root@linuxtweaks ~]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
root@linuxtweaks ~]# rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.i686.rpm

############### RHEL/CentOS 5 32-Bit #################
root@linuxtweaks ~]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
root@linuxtweaks ~]# rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.i386.rpm

############### RHEL/CentOS 4 32-Bit #################
root@linuxtweaks ~]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-1.el4.rf.i386.rpm
root@linuxtweaks ~]# rpm -Uvh rpmforge-release-0.5.2-1.el4.rf.i386.rpm

 

RHEL/Centos 64 Bit

############## RHEL/CentOS 6 64-Bit ###############33
root@linuxtweaks ~]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
root@linuxtweaks ~]# rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

############## RHEL/CentOS 5 64-Bit #################
root@linuxtweaks ~]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
root@linuxtweaks ~]# rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm

################# RHEL/CentOS 4 64-Bit #############
root@linuxtweaks ~]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el4.rf.x86_64.rpm
root@linuxtweaks ~]# rpm -Uvh rpmforge-release-0.5.2-2.el4.rf.x86_64.rpm

Once it’s installed and enabled you can install rar and unrar application using yum command.

Install Rar Package

root@linuxtweaks ~]#yum install rar
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
 unrar              i386            4.2.3-1.el5.rf      rpmforge			123 k

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

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

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


Complete!

Create Rar archive file

root@linuxtweaks ~]#rar a linux.rar foldername
RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help
Evaluation copy. Please register.

Creating archive linux.rar

Adding    foldername/file1                                           OK
Adding    foldername/file2                                           OK
Adding    foldername/file3                                           OK
Adding    foldername/anotherfolder/file1                             OK
Adding    foldername                                                 OK
Done

List of files/folders in archive file

root@linuxtweaks ~]#rar l linux.rar

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

Archive linux.rar

 Name                              Size   Packed Ratio  Date   Time     Attr      CRC   Meth Ver
-------------------------------------------------------------------------------
foldername/file1                    0        8   0% 29-06-15 21:51 -rw-r--r-- 00000000 m3b 2.9
foldername/file2                    0        8   0% 29-06-15 21:51 -rw-r--r-- 00000000 m3b 2.9
foldername/file3                    0        8   0% 29-06-15 21:51 -rw-r--r-- 00000000 m3b 2.9
foldername/anotherfolder/fil1       0        8   0% 29-06-15 21:51 -rw-r--r-- 00000000 m3b 2.9
 foldername                         0        0   0% 29-06-15 21:51 drwxr-xr-x 00000000 m0  2.0
-------------------------------------------------------------------------------
    5                               0       20   0%

 

 Delete a single file from archive

root@linuxtweaks ~]#rar d linux.rar foldername/file2
RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help

Deleting from linux.rar
Deleting foldername/file2
Done

 Update/Add new file in existing rar file

root@linuxtweaks ~]#rar u linux.rar linux.php 
RAR 3.80 Copyright (c) 1993-2008 Alexander Roshal 16 Sep 2008 
Shareware version           Type RAR -? for help      
Evaluation copy. Please register. 
Updating archive linux.rar 
Adding linux.php                     OK      
Done

 Secure rar archive file using password protection

root@linuxtweaks ~]#rar a -p linux.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 linux.rar

Done

 Unrar a rar archive file

Unarchive files in current location only

root@linuxtweaks ~]#rar e linux.rar
UNRAR 4.20 beta 3 freeware      Copyright (c) 1993-2012 Alexander Roshal

Extracting from linux.rar

Extracting  file1                                          OK 
Extracting  file2                                          OK
Extracting  file3                                          OK
Extracting  file1                            OK
All OK

Extract files as per their original structure

root@linuxtweaks ~]#rar x linux.rar
UNRAR 4.20 beta 3 freeware      Copyright (c) 1993-2012 Alexander Roshal

Extracting from linux.rar

Extracting  foldername/file1                                          OK 
Extracting  foldername/file2                                          OK
Extracting  foldername/file3                                          OK
Extracting  foldername/anotherfolder/file1                            OK
All OK

More help on both command

root@linuxtweaks ~]#man rar
root@linuxtweaks ~]#man unrar

 

 

Balvinder Singh

Hello, I am Balvinder Singh - DevOps Engineer with 2.5+ year of working experience with different server environments. Tag Line:-Linux | AWS| WHM |Monitoring | Virtualization | Optimization | Performance | Security | Release & Deployment. I love helping companies / clients to deploy their code / applicateions to well managed, optimized, secure server and can go extra mile to satisfy.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *