This tutorial will show you how to open, create or extract RAR files within Linux.
A RAR file is a proprietary format for compressing and archiving files. As a non “free” format, some distributions will not have the unrar packages we will be using in its default repository.
unrar is a tool designed purely for extracting archives that utilize the RAR format. It is actively maintained by RARLAB and is offered as copyrighted but free software.
Over the following sections, we will explore how to get the unrar tool on your system and utilize it to extract a RAR archive.
How to Extract or Open RAR Files on Linux
This section will show you how to open or extract a RAR file on a Linux system. We will need to use a piece of software called “unrar
” to open or extract these files.
Unrar is a terminal-based tool developed by RARLAB for extracting and opening RAR files on systems like Linux.
Installing unrar on Linux
Before you can use unrar to extract or open RAR files on your Linux system, you will need to install the package first.
In the following sections, we will show you how to install unrar using various package managers.
apt Package Manager (Debian, Ubuntu, etc)
1. Before installing the unrar package on systems that use the apt package manager, we need to perform an update.
By running the command below, you will update the cached package list.
sudo apt update
2. Once the package list update completes, run the following command to install unrar to your Debian-based system.
sudo apt install unrar
dnf Package Manager (CentOS, RHEL)
1. Installing the unrar utility on Linux systems that use the dnf package manager is as straightforward as running the command below.
sudo dnf install unrar
yum Package Manager (Fedora)
1. For systems that utilize the yum package manager, such as Fedora, you can install unrar to the operating system by using the command below.
sudo yum install unrar
pkg Package Manager (FreeBSD)
1. Finally, for FreeBSD it is possible to install the unrar utility by using the following command on
sudo pkg install unrar
Using unrar to Extract rar Files on Linux
The key usage of the unrar utility is to extract files from a RAR file. The most basic way to do this is to extract files without using the archived path.
By extracting without the archived path, unrar will extract all files to either the current working directory or the one you specify.
Below you can see the syntax for using the unrar utility to extract files from a RAR file on Linux.
unrar e FILENAME [DIRECTORY]
Example of Extracting a RAR File to the Current Directory
Extracting a RAR file to the current directory on Linux is as straightforward as using “unrar
” followed by the “e
” option, then finally, the path to the file you want to extract.
Using the unrar utility like this on Linux will extract the files to your current working directory.
For example, to extract a RAR archive with the name “pimylifeup.rar
“, we would use the following command.
unrar e pimylifeup.rar
Below is an example of what will be output after extracting an archive.
UNRAR 6.11 beta 1 freeware Copyright (c) 1993-2022 Alexander Roshal
Extracting from pimylifeup.rar
Extracting document.word OK
Extracting readme.txt OK
Extracting index.html OK
All OK
Example of Extracting a RAR File to a Specific Directory
It is possible to extract files to a specific directory using the unrar tool on Linux.
All you need to do to achieve this is to specify a directory after the path to the file you want to extract.
For example, if we wanted to extract the contents of our “pimylifeup.rar
” archive to the “/home/pimyubu/example
” directory, we would use the command below.
unrar e pimylifeup.rar /home/pimyubu/example
With the result below, you can see that unrar extracted the files to the specified directory.
UNRAR 6.11 beta 1 freeware Copyright (c) 1993-2022 Alexander Roshal
Extracting from pimylifeup.rar
Creating /home/pimyubu/example OK
Extracting /home/pimyubu/example/document.word OK
Extracting /home/pimyubu/example/readme.txt OK
Extracting /home/pimyubu/example/index.html OK
All OK
Example of Extracting a RAR File on Linux to the Archived Path
If your RAR archive contains archived paths for each file, you can use unrar to extract files to those paths.
Using unrar like this is a good way to restore files from a backup to their original positions.
To extract files like this, you need to replace the “e
” option, with the “x
” option, as shown in our example below.
unrar x pimylifeup.rar
Below you can see that the unrar tool extracted files back to where we originally archived them on our Linux system.
UNRAR 6.11 beta 1 freeware Copyright (c) 1993-2022 Alexander Roshal
Extracting from pimylifeup.rar
Extracting /home/pimyubu/Documents/document.word OK
Extracting /home/pimyubu/Documents/readme.txt OK
Extracting /home/pimyubu/Documents/index.html OK
All OK
Please note, you will need to archive directories using a full path for this to work.
Listing the Content of a RAR File on Linux
You can use the unrar tool on Linux to list the contents of a RAR archive file.
To list files from inside a RAR archive you need to use the “l
” option followed by the path to that particular archive.
unrar l FILENAME
Example of Listing Contents of a RAR File
To show how this works, let us use the following command to list the contents of the “pimylifeup.rar
” RAR archive.
unrar l pimylifeup.rar
Below you can see that the unrar tool output the name of each file, its size, attributes, and the date it was last modified.
UNRAR 6.11 beta 1 freeware Copyright (c) 1993-2022 Alexander Roshal
Archive: pimylifeup.rar
Details: RAR 5
Attributes Size Date Time Name
----------- --------- ---------- ----- ----
-rw-rw-r-- 9 2022-11-30 20:11 document.word
-rw-rw-r-- 5 2022-11-30 20:10 readme.txt
-rw-rw-r-- 0 2022-11-30 20:09 index.html
----------- --------- ---------- ----- ----
14 3
Testing a RAR File on Linux
You can also use the unrar utility on Linux to test the validity of a RAR archive. This functionality is useful for testing whether an archive has been corrupted.
To test whether a RAR file is valid, use the “t
” option followed by the path to the archive you want to validate.
unrar t FILENAME
Example of Testing the Contents of a RAR Archive
To showcase how you can test the validity of a RAR archive, we will utilize it on our “pimylifeup.rar
” archive.
All we need to do is use the “t
” option, followed by the archive we want to validate.
unrar t pimylifeup.rar
The result below shows that unrar tested each file in our archive, and each was successfully validated.
UNRAR 6.11 beta 1 freeware Copyright (c) 1993-2022 Alexander Roshal
Testing archive pimylifeup.rar
Testing document.word OK
Testing readme.txt OK
Testing index.html OK
All OK
Conclusion
At this point in the guide, you should know how to extract RAR files on Linux using the unrar utility.
Please comment below if you have any issues with extracting or viewing the contents of a RAR archive on Linux.
If you found this tutorial helpful, we have many guides that cover many other aspects of the Linux operating system.