Open RAR File / Extract RAR Files Under Linux or UNIX

How do I open rar archive files under a Linux or UNIX or macOS X operating system?

RAR files are in compressed archive format, if you have downloaded rar files from the Internet, you need to unpack or unrar them (extract rar files). RAR is a proprietary file format for data compression and archiving, developed by Eugene Roshal. [donotprint][/donotprint]The command used to extract these files is called “unrar”. By default, unrar is not being installed on Linux, FreeBSD or UNIX like operating system. You can install unrar command with the help of apt-get or yum command. (See below for Windows XP / 7 unrar infomation.)

Install unrar command

If you are using a Debian or Ubuntu Linux, you need to type apt-get command or apt command as follows to install unrar program:
$ sudo apt-get install unrar
OR
$ sudo apt install unrar
If you are using a CentOS / RHEL, use the yum command as follows (see discussion below for more):
# yum install unrar
If you are using Fedora Linux, use the dnf command:
$ sudp dnf install unrar
If you are using FreeBSD Unix, use the pkg command:
# pkg install unrar
If you are using OpenBSD Unix, use the pkg_add command:
# pkg_add -v unrar
If you are using macOS Unix and Homebrew, use the brew command:
$ brew install unrar
If any of above, methods is not working for your version of Unix/Linux, download binary package from official rarlab site:
$ cd /tmp
## 32 bit linux ##
$ wget https://www.rarlab.com/rar/rarlinux-5.5.0.tar.gz

OR for 64 bit Linux version:
$ wget http://www.rarlab.com/rar/rarlinux-x64-5.3.b4.tar.gz
Next, untar the file with tar command, enter:
$ tar -zxvf rarlinux-*.tar.gz
Both unrar and rar commands are located in rar sub-directory. Just cd to rar directory, type:
$ cd rar
$ ./unrar

Now copy rar and unrar file to /usr/local/bin directory, type:
$ sudo cp rar unrar /usr/local/bin

How to use unrar Command

The unrar command supports various options, below are common options that you need to for extracting files.

Task: Extract rar (unpack) File

To extract file.rar file into the current directory, enter:
$ unrar e file.rar
Sample outputs:

UNRAR 5.50 freeware      Copyright (c) 1993-2017 Alexander Roshal
 
 
Extracting from file.rar
 
Extracting  adduser.conf                                              OK 
Extracting  apg.conf                                                  OK 
Extracting  appstream.conf                                            OK 
Extracting  brltty.conf                                               OK 
Extracting  ca-certificates.conf                                      OK 
Extracting  sensors3.conf                                             OK 
Extracting  sysctl.conf                                               OK 
All OK

Task: List (l) file inside rar archive:

$ unrar l file.rar

List all files stored inside a rar archive

Task: To extract (x) files with full path type command:

$ unrar x file.rar
Sample outputs:

UNRAR 5.50 freeware      Copyright (c) 1993-2017 Alexander Roshal
 
 
Extracting from file.rar
 
Creating    etc                                                       OK
Extracting  etc/adduser.conf                                          OK 
Extracting  etc/apg.conf                                              OK 
Extracting  etc/appstream.conf                                        OK 
Extracting  etc/brltty.conf                                           OK 
Extracting  etc/ca-certificates.conf                                  OK 
Extracting  etc/sensors3.conf                                         OK 
Extracting  etc/sysctl.conf                                           OK 
All OK

To test (t) integrity of archive, file type command:

$ unrar t file.rar
Sample outputs:

UNRAR 5.50 freeware      Copyright (c) 1993-2017 Alexander Roshal
 
 
Testing archive file.rar
 
Testing     etc/adduser.conf                                          OK 
Testing     etc/apg.conf                                              OK 
Testing     etc/appstream.conf                                        OK 
Testing     etc/brltty.conf                                           OK 
Testing     etc/ca-certificates.conf                                  OK 
Testing     etc/sensors3.conf                                         OK 
Testing     etc/sysctl.conf                                           OK 
All OK

Getting help about unrar command

Type the following command:
$ man unar
OR
$ unrar | more
Sample outputs:

unrar
 
UNRAR 5.50 freeware      Copyright (c) 1993-2017 Alexander Roshal
 
Usage:     unrar <command> -<switch 1> -<switch N> <archive> <files...>
               <@listfiles...> <path_to_extract>
 
<Commands>
  e             Extract files without archived paths
  l[t[a],b]     List archive contents [technical[all], bare]
  p             Print file to stdout
  t             Test archive files
  v[t[a],b]     Verbosely list archive contents [technical[all],bare]
  x             Extract files with full path
 
<Switches>
  -             Stop switches scanning
  @[+]          Disable [enable] file lists
  ad            Append archive name to destination path
  ag[format]    Generate archive name using the current date
  ai            Ignore file attributes
  ap<path>      Set path inside archive
  c-            Disable comments show
  cfg-          Disable read configuration
  cl            Convert names to lower case
  cu            Convert names to upper case
  dh            Open shared files
  ep            Exclude paths from names
  ep3           Expand paths to full including the drive letter
  f             Freshen files
  id[c,d,p,q]   Disable messages
  ierr          Send all messages to stderr
  inul          Disable all messages
  kb            Keep broken extracted files
  n<file>       Additionally filter included files
  [email protected]            Read additional filter masks from stdin
  [email protected]<list>      Read additional filter masks from list file
  o[+|-]        Set the overwrite mode
  ol[a]         Process symbolic links as the link [absolute paths]
  or            Rename files automatically
  ow            Save or restore file owner and group
  p[password]   Set password
  p-            Do not query password
  r             Recurse subdirectories
  sc<chr>[obj]  Specify the character set
  sl<size>      Process files with size less than specified
  sm<size>      Process files with size more than specified
  ta<date>      Process files modified after <date> in YYYYMMDDHHMMSS format
  tb<date>      Process files modified before <date> in YYYYMMDDHHMMSS format
  tn<time>      Process files newer than <time>
  to<time>      Process files older than <time>
  ts[m|c|a]     Save or restore file time (modification, creation, access)
  u             Update files
  v             List all volumes
  ver[n]        File version control
  vp            Pause before each volume
  x<file>       Exclude specified file
  [email protected]            Read file names to exclude from stdin
  [email protected]<list>      Exclude files listed in specified list file
  y             Assume Yes on all queries

How do I open rar file under MS-Windows XP/NT/2000/7/8/10?

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.