Centos 6/RHEL install and use Unrar

Sometimes you need to extract rar files or rar them up for a variety of reasons, often because they have come to you from a Windows environment, and you will need a program which can deal with them. Unrar is useful for this and it can be used on its own at the command line, or in conjunction with a GUI such as Xarchiver. (Xarchiver will not work on rar files unless you install unrar as below).

Using unrar in Centos 6/RHEL is simply a matter of installing it from the rpmforge repo, so get that first.

$ sudo rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm

Disable it with

$ sudo vi /etc/yum.repos.d/rpmforge.repo

See Vi and Vim commands

Set enabled to '0' , now install unrar

$ sudo yum -y --enablerepo=rpmforge install unrar

Below are some example commands to unrar files, you will usually use 'x' or 'e' to extract, 'unrar -h' for more options.

$ unrar x <file_name>.rar      Extract with full path

$ unrar e -kb <file_name>.rar  (Keep broken)

$ unrar l <file_name>.rar      list files inside

$ unrar e <file_name>.rar      dump files excluding folders

For multiple rar files which are numbered (for example) .r00 .r01
.r02 etc, just start at the first file name and the others will automatically be extracted.

Below is a loop to unrar multiple files

$ for i in *.rar

  mkdir "${i/.rar}"
  cd "${i/.rar}"
  unrar e "../$i"
  cd ..

Install from source

If you prefer to install unrar from the vendors source

$ sudo su

# cd /usr/src ; wget http://www.rarlab.com/rar/unrarsrc-4.0.2.tar.gz ; tar xvfz unrarsrc-4.0.2.tar.gz ; cd unrar ; ln -s makefile.unix Makefile ; make clean ; make ; make install

But check the http path as it could alter over time.

For more repositories see repos page.

Labels: , ,