How to Open, Extract RAR Files in Linux

How to Open, Extract RAR Files in Linux

Roshal Archive Compressed (RAR) file is a compressed file that is popularly used by many users across the world. It even allows you to split a single large file into multiple compressed RAR files for convenience. Windows users use WinRAR utility tool to open and extract RAR files. But how to extract RAR files in Linux? In this article, we will learn how to do this.

How to Open, Extract RAR Files in Linux

The simplest way to extract RAR files in Linux, is to use unrar command. Here is the command to install it on Ubuntu/Debian systems.

$ sudo apt-get install unrar
Or

$ sudo apt install unrar

Here is the command to instal unrar command in RHEL/Fedora/CentOS systems.

$ sudp dnf install unrar

You can also install it from source if you want to. Here are the commands to it. We will need to download & install the latest version from rarlab.com. If you want to install 32-bit version of unrar, then replace 64 with 32 in the commands below.

$ cd /tmp
$ wget https://www.rarlab.com/rar/rarlinux-x64- tar.gz
$ tar –zxvf rarlinux-x64-tar.gz
$ cd rar
$ sudo cp –v rar unrar /usr/local/bin/

unrar utility tool offers tons of useful options to perform different kinds of operations. Now we will look at some of the most commonly used options. Please note, unlike other Linux commands, we do not need to add hyphen ‘-‘ before each option in unrar.

Once unrar is installed, you can unrar a file using the following command syntax.

$ unrar e filename.rar

Here is the command to extract file data.rar at /home/ubuntu. You will need to provide full path to the file unless the file is located in your present working directory.

$ unrar e /home/ubuntu/data.rar

Once you have installed unrar command, you can also right click on the file and select the unrar option in GUI.

If you want to extract the file in another directory mention the path to it after the .rar filename. Here is the command to extract file to /home/projects folder

$ unrar e data.rar /home/projects

If you want to extract the file in original directory, use x option.

$ unrar x filename.rar

Sometimes you may want to view the content of rar file before extracting it, especially if it is a big file. You can do this using the following ‘l’ option.

$ unrar l filename.rar

Here is the command to view contents of data.rar file in /home/ubuntu

$ unrar l /home/ubuntu/data.rar

Often when you download a file from internet, you may find that it has become corrupted. For this purpose, it is advisable to test its integrity before you extract it. You can do this using ‘t’ option.

$ unrar t /home/ubuntu/data.rar

The above command will do a complete check on all contents of the rar file and give result.

As you can see, unrar command will allow you to extract, view contents and test compressed file. But it does not allow you to create a RAR file or compress a file/directory into a RAR file. For that purpose, you need to use RAR utility tool.

Installing RAR utility

Here is the command to install RAR utility tool.

$ sudo apt-get install rar
$ sudo dnf install rar
$ yum install rar

Once you have installed RAR utility, you can create a RAR file using ‘a’ option as shown below.

$ rar a filename.rar filename

Here is an example to create RAR file for data.txt.

$ rar a data.rar data.txt

RAR utility also provides some nifty features that are not available in Unrar tool. For example, you can also use it to delete a specific file from the .rar file. Basically you need to mention one or more file names that you want to be deleted from the .rar file.

$ rar d filename.rar file_to_be_deleted

Let us say you have data.rar file which consists of file1, file2, file3, etc. and you want to delete only file2 from the .rar file then here is the command for it.

$ rar d data.rar file3

If you have accidentally deleted one or more files from a .rar file you can recover it using r option. You can also use this option to repair a .rar file.

$ rar d filename.rar

On the other hand, if you want to add one or more files to an existing file, you can do it with ‘u’ option which basically updates the rar file. Here is the command to to add files file1 and file 2 to data.rar file.

$ rar u data.rar file1 file2

You can also set password to your rar file to prevent accidental extraction or opening. You can do this using -p option as shown below.

$ rar a –p filename.rar

In the above command, you will be prompted for password and its confirmation.

Once you enter the password, from then onwards, whenever you try to extract the file, you will prompted for the password.

If you want to remove password from such a file, then you need to decompress it using the password and recompress it into a new file, and then delete the old password protected file.

In this article, we have learnt how to open, extract RAR file using unrar tool. We have also learnt many commonly used options of unrar utility tool. In addition, we have also learnt how to compress files using rar utility tool.

Also read:

How to Implement SSL/TLS in Apache Tomcat
How to Solve NPM error ‘npm ERR! code ELIFECYCLE’
How to Get Value from Text Input in JavaScript
How to Add Property to JavaScript Object Using Variable
How to Set/Unset Cookie in jQuery

Leave a Reply

Your email address will not be published. Required fields are marked *