166

I have a file with .rar extension, ex: foo.rar

I want to extract content from that file, how do I extract it?

shas
  • 2,688

11 Answers11

135

You can install unrar - "Unarchiver for .rar files" or unp - "unpack (almost) everything with one command"

To unrar a file:

  • unrar x <myfile>

To unp a file:

  • unp <myfile.rar>

Since unrar is not open source, some distros might not have it in their package manager already. If it's not, try unrar-free.

Notice that unrar x <myfile> will preserve directory structure in archive, in difference with unrar e <myfile> which will flatten it

VanDavv
  • 35
cutrightjm
  • 5,290
  • 3
    There is also a rar command. It is binary-only and a bit less easy to use, but can open some files that unrar cannot. – Wouter Verhelst Dec 01 '15 at 06:47
  • On my Linux Mint 18.2 installation, unrar appears to be already installed and available by default. – Christos Hayward Sep 18 '17 at 17:15
  • 1
    I needed to first install it by running sudo apt install unrar. This is the official version and it has license prohibing some usage (no compression, only decompression). So you can also use the free version instead: sudo apt-get install unrar-free. – tsveti_iko May 12 '20 at 16:29
  • 5
    NON FREE terminal command for "basic data interchange format" is not a good option. – Peter Krauss May 23 '20 at 22:41
  • This unp is really awesome! – Ahmad Nov 10 '22 at 09:47
77

You can use unar. This is not related to the non-free unrar, it's free software.

Easy to use:

 unar file.rar
  • @vonbrand: availability depends on the specific GNU/Linux distribution. For example unar is available for Parabola GNU/Linux-libre. Anyway I didn't mention "unrar", and unar != unrar –  Feb 23 '16 at 18:06
  • There is also something called unrar-free. – neverMind9 Oct 30 '18 at 21:00
  • 1
    If rar is not open source, so much that 7-Zip on OSS distributions will not ship with it, how did unar manage to include it? – palswim Jan 31 '19 at 00:57
  • 3
    @palswim, rar is simply a proprietary format and the rar tool is an implementation (which has a non-open license). unar is another implementation that is free. Fedora removed the non-free rar tool due to its license, not because of anything regarding the rar format itself – Neowizard Mar 09 '19 at 07:59
  • 3
    Hum.. functional problem in unar that unrar not have, a file of 49750384 bytes, "Failed! (Attempted to read more data than was available)". Sorry, bad program. – Peter Krauss May 24 '20 at 13:16
  • this worked for me on raspberry pi – Ahmed Apr 10 '23 at 11:18
  • I tried unrar first but it created 82TB files instead of 500kb files. unar worked great, no weird sparse file problems, so highly recommended. – KJ7LNW Jan 25 '24 at 21:04
  • When unrar cannot create directory, try unar, it works fine. – miket Feb 01 '24 at 05:38
17
sudo apt-get install p7zip  # debian based systems
sudo yum install p7zip      # CentOS based systems    
7zr x myfile.rar

On Windows I rely on 7zip for rar and every other archive file, and it works on Linux, too.

phyatt
  • 607
12

You can get unar from fedora repo, it's open and licence-pure:

dnf install unar
unar file.rar
shcherbak
  • 493
  • 2
  • 10
  • 1
    Not available. unrar is not open source (it is forbidden to analyze the code to reverse engineer a compression program), so Fedora won't ship it. – vonbrand Feb 23 '16 at 10:24
  • su -c 'dnf install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm' – shcherbak Feb 24 '16 at 11:06
  • dnf install unrar – shcherbak Feb 24 '16 at 11:07
  • also you can use unar for fedora 23. did the author of the question asked about feora or opensource sollution or about unix rar sollution? @vonbrand – shcherbak Feb 24 '16 at 11:10
  • To install on debian, use: sudo apt-get install unar – VectorVortec Mar 02 '18 at 18:12
7

For Linux Ubuntu and Mint

Installation

sudo apt install unar

Usage

unar file_name.rar

More info

  • Extract an archive to the current directory: unar {{archive}}

  • Extract an archive to the specified directory: unar -o {{path/to/directory}} {{archive}}

  • Force overwrite if files to be unpacked already exist: unar -f {{archive}}

  • Force rename if files to be unpacked already exist: unar -r {{archive}}

  • Force skip if files to be unpacked already exist: unar -s {{archive}}

muru
  • 72,889
dipenparmar12
  • 171
  • 1
  • 5
6

Note that unrar is not open source (the license to the available source forbids using it to reverse engineer the compression, which violates point 6 "No Discrimination Against Fields of Endeavor" of the Open Source Definition), and thus will not be shipped by Fedora.

Go to Rar Labs, check out the source for unrar (be careful, the version might have changed!), build and install (you'll need g++ and make), preferably for your account only:

$ tar zxf unrarsrc-5.3.11.tar.gz
$ cd unrar
$ make DESTDIR=$HOME all
$ make DESTDIR=$HOME install-unrar

Add $HOME/bin to your PATH, and you are all set.

Yes, there is a RPM offered. I would't touch it with the proverbial 10 feet pole, more often than not third parties have no clue on how to create a correct RPM (it isn't exactly rocket science, but there are lots of details that have to be just right, see e.g. Fedora's guidelines). Besides, there are differences between Fedora versions, "one size fits all" can't cut it.

Update: There is a RPM for unrar version 6.0.5 in the RPM Fusion repository for Fedora 34. The license is cited as "Freeware with further limitations".

vonbrand
  • 18,253
5

On Ubuntu and Fedora (and perhaps other distributions as well), you have a GUI solution, Archive Manager. It provides extraction of such archive files as .rar files.

  • 1
    It is rare to see a least popular answer (which was showed at the very bottom before my up-vote), to provide a simplest solution! Thanks @MAChitgarha! For future readers: it is likely that your distro does NOT link the .rar extension name to Archive Manager. With the hint of this answer, I open the Archive Manager manually, and then use it to open the .rar file. It works like a charm! – RayLuo Jan 06 '21 at 06:51
  • @RayLuo Really thanks for your comment! Personally, .rar is linked to be opened with Archive Manager in Nautilus (maybe this is the default on Gnome), and even there is an option in the menu here (Fedora Gnome). Maybe something is out-of-date there, or you're not on Gnome? By the way, I'm happy to provide a simple solution for you! – MAChitgarha Jan 06 '21 at 14:04
  • 1
    it sounds like it would work out-of-box on Gnome, as it should be. With lots of Desktop Environments in Linux world, I happen to be not on Gnome. Still thank you for the hint. – RayLuo Jan 07 '21 at 03:25
2

Use RAR rar e <filename> it comes with most distros. Created by brother of Eugene Rosahal who is the developer of RAR files.

2

If you do not have sudo rights, 7zip solved the problem for me. You need conda/miniconda installed beforehand:

conda install conda-forge::p7zip

And then

7z x foo.rar
Bin Yu
  • 3
  • 2
  • 1
    Really wanted this to work but conda says that it doesn't exist: `$ conda install -c conda-forge 7zip

    PackagesNotFoundError: The following packages are not available from current channels:

    • 7zip

    Current channels:

    • https://conda.anaconda.org/conda-forge/linux-64
    • https://conda.anaconda.org/conda-forge/noarch
    • https://repo.anaconda.com/pkgs/main/linux-64
    • https://repo.anaconda.com/pkgs/main/noarch
    • https://repo.anaconda.com/pkgs/r/linux-64
    • https://repo.anaconda.com/pkgs/r/noarch`
    – ojunk May 24 '23 at 16:11
0

I'd suggest using a nearest available file manager, either Norton-like (Midnight Commander, Double Commander, Tux Commander, etc., whatever is present in your distribution) or window-based (as Dolphin). Most of them have enough intelligence to open all kinds of archives in a manner suitable for manual contents exploring, but, sometimes, they use external tools. For instance, my Kubuntu suggests Ark in such cases. They would need an external tool, as unrar, for accessing proprietary archive formats; if so, install the latter using a package manager.

If you want to extract the entire archive or a single specified file, unrar e extracts without full path, and unrar x also makes intermediate directories.

Netch
  • 2,529
  • 1
    Since unrar is not open source, Fedora won't ship support for it in any form. – vonbrand Feb 23 '16 at 12:59
  • 1
    @vonbrand Ubuntu provides both unrar and unrar-free. If Fedora can't include the latter, it's not a license issue. – Netch Feb 27 '16 at 20:04
  • @vonbrand moreover, there is no word for Fedora from original author. Your approach to limit question to the only non-most-used distribution is destructive. – Netch Feb 27 '16 at 20:09
  • 1
    Fedora won't ship anything that isn't open source. Unrar has strings attached ("don't use it to reverse engineer RAR compression"), so definitely not open source, and it is a licence issue. – vonbrand Feb 08 '20 at 14:45
  • FYI: Nice try. But "Midnight Commander" errors out with a message "... urar: 1: ... not found". I guess it would still need the command line urar to exist beforehand. – RayLuo Jan 06 '21 at 06:53
0

Install the unrar package. On Fedora, for eample, you can do so with:

sudo yum install unrar

Then, use it to extract the files:

unrar e filename.rar
terdon
  • 242,166