How to Open and Extract RAR Files in Linux?

How to Open and Extract RAR Files in Linux?

The RAR file format compresses large files into smaller ones so they can be sent easily over the internet. When downloading a .rar file from the web, we need to use a rar tool to extract (uncompress) its contents.

The RAR file format is freely available for Windows operating systems—but the rar tool, which handles compressed files, isn’t installed on Linux by default.

This article will explain how to install the Unrar command-line tool on a Linux system.

Step 1: Installing Unrar on Linux

The program of apt or apt-get can be used to install unrar on Debian and Ubuntu-based distributions.

Code:
$ sudo apt-get install unrar
Or
$ sudo apt install unrar
Using RHEL-based distributions, use DNF or yum to install it.

Code:
$ sudpdnf install unrar
You will need to download and install a recent version of rar/unrar for users of other Linux distributions by the following command.

Code:
--------------- On 64-bit ---------------

# cd /tmp
# wget https://www.rarlab.com/rar/rarlinux-x64-612.tar.gz
# tar -zxvf rarlinux-x64-612.tar.gz
# cd rar
# sudo cp -v rarunrar /usr/local/bin/

--------------- On 32-bit ---------------

# cd /tmp
# wget https://www.rarlab.com/rar/rarlinux-x32-612.tar.gz
# tar -zxvf rarlinux-x32-612.tar.gz
# cd rar
# sudo cp -v rarunrar /usr/local/bin/

Step 2: How to Extract a Linux file of RAR File


To extract or open the file of RAR use this command: unrar e in the directory where you work currently.

Code:
# unrar e hoststud.rar
For extracting and opening the file of RAR and placing its contents in another location, use the unrar e command with an option that specifies where you want to put the files.

Code:
# unrar e hoststud /home/
To extract a RAR file with its original directory structure, use the below command: unrar x (source). According to the structure given, it would start to extract the command output:

Code:
# unrar x hoststud.rar

Step 3: How to Add a RAR File to Linux


For listing the archive file content, use the mentioned command unrar l. You can see the list of files logged in time, date, and size at the time of creation.

Code:
unrar l hoststud.rar

Step 4: Testing Your RAR File in Linux


Here, we are testing the archive file for integrity, using the option unrar t. The command mentioned below is about to perform the file integrity and checks the file status too.

Code:
unrar t hoststud.rar
The unrar command can be used to extract, list, and test RAR files—but it has no option for creating them. So we have to start the installation of the tools command-line RAR for creating the archive files.

Step 5: To install RAR on Linux, follow these steps

You can install the RAR command option in Linux by executing this command:

Code:
# sudo apt-get install rar
# sudo DNF install rar
# yum install rar

Step 6: Create a RAR File in Linux


Run the command mentioned below for creating the RAR archive file. You can start using the mentioned command with the rar option:

Code:
rar a hoststud.rarhoststud


Step 7: How to Delete files from the Archive


To remove a file from an archive, run this command.

Code:
rar d filename.rar


Step 8: How to Recover a Deleted File


When trying to recover or fix an archive file, it is advisable to run the command with the option

Code:
rar r.
rar r filename.rar

Step 9: Step to Update Archives


To add or update files in an existing archive, use the command rar u.

Code:
rar u hoststud.rarhoststud.sql
Confirm that hoststud.sql is one of the files added to your archive file.

Code:
rar l hoststud.rar
Step 10: Setting a password for archive files

To password-protect, a RAR archive file, use the command line option rar a –p.

Code:
rar a -p hoststud.rar
Let us extract the archive file and see whether a password prompt appears.

Code:
rar x hoststud.rar
Step 11: How to Protect Your Archives

RAR Tool lets you lock an archive file after extracting its contents.

Code:
rar k hoststud.rar


Summary


We have discussed all the steps to open, extract and protect the rar files. Follow the steps to accomplish your task.
Author
kumkumsharma
Views
2,583
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from kumkumsharma

Top