Linux unrar Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will learn how to use the Linux unrar command to extract files from RAR archives. We will cover the steps to install the unrar package on Ubuntu 22.04, extract a single RAR file, and extract a multi-part RAR archive. The unrar command is a useful tool for working with compressed files, and this lab will provide practical examples to help you become more proficient in using it.

The lab will guide you through the process of installing the unrar package, which is necessary to extract RAR files on your Ubuntu 22.04 system. You will then learn how to extract a single RAR file and a multi-part RAR archive, which can be helpful when working with compressed data.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux/FileandDirectoryManagementGroup -.-> linux/cd("`Directory Changing`") linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") linux/PackagesandSoftwaresGroup -.-> linux/wget("`Non-interactive Downloading`") linux/PackagesandSoftwaresGroup -.-> linux/apt("`Package Handling`") subgraph Lab Skills linux/cd -.-> lab-422979{{"`Linux unrar Command with Practical Examples`"}} linux/sudo -.-> lab-422979{{"`Linux unrar Command with Practical Examples`"}} linux/wget -.-> lab-422979{{"`Linux unrar Command with Practical Examples`"}} linux/apt -.-> lab-422979{{"`Linux unrar Command with Practical Examples`"}} end

Install unrar Package on Ubuntu 22.04

In this step, we will install the unrar package on our Ubuntu 22.04 system. The unrar package is a command-line tool that allows us to extract files from RAR archives.

First, let's update the package index:

sudo apt-get update

Example output:

Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Fetched 324 kB in 1s (324 kB/s)
Reading package lists... Done

Next, install the unrar package using the following command:

sudo apt update
sudo apt-get install -y unrar

Example output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  unrar
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 75.5 kB of archives.
After this operation, 217 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/multiverse amd64 unrar amd64 1:6.0.2-1.1build1 [75.5 kB]
Fetched 75.5 kB in 0s (0 B/s)
Selecting previously unselected package unrar.
(Reading database ... 63099 files and directories currently installed.)
Preparing to unpack .../unrar_1%3a6.0.2-1.1build1_amd64.deb ...
Unpacking unrar (1:6.0.2-1.1build1) ...
Setting up unrar (1:6.0.2-1.1build1) ...
Processing triggers for man-db (2.10.2-1) ...

The unrar package is now installed on your Ubuntu 22.04 system.

Extract a Single RAR File

In this step, we will learn how to extract a single RAR file using the unrar command.

First, let's download a sample RAR file to our ~/project directory:

cd ~/project
wget https://github.com/mebeim/unrar-examples/raw/master/single.rar

Example output:

--2023-04-27 12:34:56--  https://github.com/mebeim/unrar-examples/raw/master/single.rar
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1011 (1.0K) [application/octet-stream]
Saving to: 'single.rar'

single.rar          100%[===================>]   1.01K  --.-KB/s    in 0s

2023-04-27 12:34:56 (25.5 MB/s) - 'single.rar' saved [1011/1011]

Now, let's extract the contents of the RAR file using the unrar command:

unrar x single.rar

Example output:

UNRAR 6.02 freeware      Copyright (c) 1993-2022 Alexander Roshal

Extracting from single.rar

Extracting  example.txt                     OK
All OK

The unrar x command extracts the contents of the RAR file to the current directory.

Extract a Multi-Part RAR Archive

In this step, we will learn how to extract a multi-part RAR archive using the unrar command.

First, let's download the multi-part RAR archive to our ~/project directory:

cd ~/project
wget https://github.com/mebeim/unrar-examples/raw/master/multi-part.part1.rar
wget https://github.com/mebeim/unrar-examples/raw/master/multi-part.part2.rar

Example output:

--2023-04-27 12:34:56--  https://github.com/mebeim/unrar-examples/raw/master/multi-part.part1.rar
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1011 (1.0K) [application/octet-stream]
Saving to: 'multi-part.part1.rar'

multi-part.part1.rar 100%[===================>]   1.01K  --.-KB/s    in 0s

2023-04-27 12:34:56 (25.5 MB/s) - 'multi-part.part1.rar' saved [1011/1011]

--2023-04-27 12:34:56--  https://github.com/mebeim/unrar-examples/raw/master/multi-part.part2.rar
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1011 (1.0K) [application/octet-stream]
Saving to: 'multi-part.part2.rar'

multi-part.part2.rar 100%[===================>]   1.01K  --.-KB/s    in 0s

2023-04-27 12:34:56 (25.5 MB/s) - 'multi-part.part2.rar' saved [1011/1011]

Now, let's extract the contents of the multi-part RAR archive using the unrar command:

unrar x multi-part.part1.rar

Example output:

UNRAR 6.02 freeware      Copyright (c) 1993-2022 Alexander Roshal

Extracting from multi-part.part1.rar

Extracting  example.txt                     OK
All OK

The unrar x command automatically detects and extracts the contents of the multi-part RAR archive.

Summary

In this lab, we first learned how to install the unrar package on an Ubuntu 22.04 system, which is a command-line tool for extracting files from RAR archives. We then explored how to extract a single RAR file using the unrar command, as well as how to extract a multi-part RAR archive. These steps provide practical examples of working with RAR files in a Linux environment.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like