Skip to main content
How To

Use unrar in Ubuntu

Got a rar file to deal with? Learn how to use unrar in Ubuntu command line.

Sagar Sharma

While downloading packages from the internet, you'd probably get it in form of the .rar package.

So how do you extract files from the compressed .rar format? It is pretty easy as there is a CLI utility made for that specific task named unrar.

In this guide, I will walk you through the following:

  • Installation of unrar command in Ubuntu
  • How to use the unrar command in Ubuntu

So let's start with the installation part.

How to install unrar in Ubuntu

The unrar utility does not come pre-installed in Ubuntu and it is not available in their default repository!

So for the installation, first, you'd have to enable the multiverse repository in Ubuntu (if you haven't already) using the following:

sudo add-apt-repository multiverse

Once done, use the following command to install the unrar utility in Ubuntu:

sudo apt install unrar

That's it! Now, let's have a look at how it can be used.

How to use the unrar command in Ubuntu

To use any command, it is mandatory to know the syntax otherwise, it will throw errors. So here's the simple syntax for the unrar command:

unrar [command] [-switch] [file]

Here,

  • [command] is used to tweak the core functionality of the unrar command such as testing archives, extracting files, etc.
  • [-switch] is optional and can be thought of as a set of additional features provided by the unrar command which includes features like setting up passwords, disabling comments, etc.
  • [file] is where you'd enter the filename or give the absolute path to the unrar command.

Now, let's have a look at some examples of the unrar command.

1. How to extract a RAR file in Ubuntu

To extract a RAR file, all you have to do is use the e option with the unrar command and then it will extract files in the same directory where the RAR file exists:

unrar e Filename.rar
extract RAR file using the unrar command

But what if you want to extract files to a different directory?

Simple, at the end of the command, you'd have to provide the path where you want to extract the RAR file:

unrar -e Filename.rar /path/to/extract/RAR

So let's say I want to extract the RAR file to the Tutorial directory, then, I will be adding the absolute path to that directory:

unrar e Files.rar ~/Tutorial
extract RAR file to different directory using the unrar command

2. How to extract a RAR to an original directory structure

You may want to extract the RAR file in its original directory structure.

To do so, use the x flag, it will mimic the original file path in the same directory where the RAR file exists:

unrar x Filename.rar
extract RAR files in their original directory structure

And as you can see, it creates the directors to mimic the original directory structure.

3. How to list the file contents of a RAR file

The unrar command also allows you to verify the file contents of the RAR file.

And to do so, you can use the l option and append the RAR filename:

unrar l Filename.rar
list the file contents of the rar file using the unrar command

And as you can see, it gets the file permissions, time, size, filename, and total files in the RAR archive.

Extract Zip File to a Folder in Ubuntu
Learn about extracting zip files to a folder of your choice in Ubuntu command line. This way, your current directory is not messed up with the contents of the zip file.

4. How to test the integrity of the RAR file

To test the integrity of a RAR file, all you have to do is use the t option with the unrar command in shown manner:

unrar t Filename.rar
test intigrity of a RAR file using the unrar command

But what about extracting the zip files?

If you want to extract the zip files, you'd have to use the unzip command.

Don't know how to install and use it? Don't worry, the following guide covers installation with practical examples:

Unzip Files in Ubuntu Command Line
Got a zipped file? Learn how to extract a zipped file using the unzip command in the Ubuntu command line.

I hope you will find this guide helpful.

And if you have any doubts or suggestions, feel free to ask in the comments.

Sagar Sharma