While downloading packages from the internet, you'd probably get it in form of the
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]
[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
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
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
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
And as you can see, it gets the file permissions, time, size, filename, and total files in the RAR archive.
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
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:
I hope you will find this guide helpful.
And if you have any doubts or suggestions, feel free to ask in the comments.