Howto command-line unrar on Mac OS X

September 2nd, 2007, filed under Apple

Decompressing *.RAR on a Mac OS X can’t be done by default. Of course you could use UnRarX to do this job, though not my cup of tea. I like command-line utilities e.g. par2cmdline and unrar. This post will help you installing the freeware unrar command-line tool from Rarlab.

Installation

Download the full package containing both rar (shareware) and unrar (freeware) from the Rarlab website. I’ve chosen the RAR 3.70 for Mac OS X package (rarosx-3.7.0.1.tar.gz). Decompress the package (just double click on the .tar.gz file) and you will see a new folder, named rar, containing the necessary files.

Enter your terminal, which can be found in /Applications/Utilities.


Start up Terminal on your Mac, located in /Applications/Utilities

Go to the newly created rar folder with both rar and unrar. You can use the command cd to change directories.


Entering the rar folder in your terminal. See full image

Use the following command to install unrar:

~$: sudo install -c -o $USER unrar /bin

$USER is a default environment variable in the bash shell which contains your username.

Sudo requires you to enter your user password. It’s the same password you use when you log in to Mac OS X. To install rar you can use the same command:

~$: sudo install -c -o $USER rar /bin

Do a test-run to see if the installation went properly. In your terminal now enter from any location you want:

~$: unrar

When unrar is properly installed, usage information should appear explaining commands and switches you can use. To decompress a .RAR package simply use the following command which will extract all files with full path:

~$: unrar x compressed-package.rar

In your terminal it will look like this:


Example of an extracted .RAR archive within your terminal. See full image

That’s it! Have fun decompressing .RAR archives on your Mac using cool command lines.

66 Responses

Or just use Zipeg from http://www.zipeg.com

Posted by

I dont find your steps clear… what do you mean by “go to the newly created folder with both rar and unrar. Use the following command to install unrar:” ???

Do you want us to open it?

+ Now it says my shortname is an invalid argument after trying to enter my login password!

Posted by

I’ve updated the text and added some more screenshots. Hope this will make things clear.

Posted by

Thanks Robert for your explanations !

Posted by

Okay I just find the password step unclear… what do we enter for the password???

Posted by

thanks. these steps help because I wouldn’t have realized that the winrar dir actually had a freeware osx unrar in it.

Posted by

Hi, I have a load of rar files split into parts and I’d like to use unrar to read from stdin, but trying something like:

cat *.rar | unrar x /Users/Movies/

This doesn’t work and I cant see anything in the unrar docs about reading from stdin. Like you, I’d rather do this from the command line. Any ideas?

Posted by

Hello Nick. If I understand correctly you want to extract multiple rar files to a specific directory? If so, enter the directory where all the rar files are located and try the following command:

find *.rar -exec unrar x {} ~/Movies/ \;

This should work if your filenames have no white spaces. Btw, unrar is able to extract rar files that are split up into parts.

Posted by

Nick: unrar any of the split files and it will extract everything in all of them to your dir of choice.

Posted by

Thanks – I managed to do it via Terminal! I’m slowly learning Unix commands, and little tutorials like yours help. The weird thing is that when I unrar files with this or with UnrarX, it sometimes makes and empty folder. I can see the files from Terminal, though finder says there are 0 items in the folder. Weird.

Posted by

Thank You. that was very helpful.

Posted by

hi, could you give me the command to compress a complete folder to rar archives not bigger than 105,000,000 bytes each and with highest compression level?
thanx in advance!

Posted by

@ Qwertzui: Try the following command:

$ rar a -m5 -v105000000b yourarchive.rar directoryname
Posted by

thank you! i tried myself a bit and added ep1 and x switches to exclude the path to be wrapped into the archive and to prevent .ds_store files to be added.

rar a -m5 -v105000000b -ep1 -x*.DS_Store yourarchive.rar directoryname

one can add a path to yourarchive.rar (eg: /Users/xxxxx/Desktop/yourarchive.rar) to not just save it to the root directory.

Posted by

Hi, i still have problems with a multiple archive, a music album. I have an archive which is packed like this: rar.aa and rar.ab.

When i open the first one it gives an error in the end and doesn’t continue to the second archive. When i try to extract the second archive terminal says that it contains nothing.

Anyone ideas how to extract these two files, which have to be one folder in the end?

Thanks a lot!!!

Posted by

great info here, got me on my way!

got a problem tho:
the directory file (xyz.rar) is missing but all the pieces (xyz.r##) are present; Is there a way to unrar w/o xyz.rar?

Posted by

thx very much :D
this helped me out

Posted by

Thank you!

Posted by

Hi. I’ve been sent a rar.aa audio file.
Can someone advise me how to extract it on a Mac OSX system?

Posted by

Try using environment variable $USER in the instructions instead of the Robert in the image and the %ShortUserName% and all that junk. $USER should work just fine.

Posted by

also, it should install to /usr/local/bin — 3rd party binaries should not be placed in /bin

Posted by

On the surface a Mac looks so basic, but man this is complicated. Thanks for helping macnoobs like me out!

Posted by

Thanks heaps, easy to understand CHEERS!!!

1 thing if people were having trouble with this part;

$ sudo install -c -o %UserShortName% unrar /bin

U don’t have to put in ur short name, can just leave that out. That’s if it didn’t work the first time. so try;

$ sudo install -c -o unrar /bin

Hope that helps some1.

Posted by

There are two versions of unrar on the website, one being a universal binary. The universal binary doesn’t open to a folder and isn’t in a command-line format. Does anyone know what it is?

Posted by

Great! Thanks!

Posted by

Thanks!

Posted by

I’m wandering if there’s any way to make unrar pause and wait for an archive to change in size, then continue extracting (or for the next part of a multipart to become available) rather than just going ‘Unexpected end of archive’. This would be so that you could extract a file from a multipart archive as that multipart archive is downloaded. A streaming extract if you like.

Any ideas welcome!

Posted by

[...] si lo consigo. Por de pronto puedes instalar rar y unrar en línea de comandos en tu sistema con este tutorial (en [...]

Posted by

[...] si lo consigo. Por de pronto puedes instalar rar y unrar en línea de comandos en tu sistema con este tutorial (en [...]

Posted by

Vielen Dank!
Die Info hat mich weitergebracht. Super

Posted by

Very many thanks Robert. You have dug me out of a hole.

Posted by

Cool stuff, I was looking for a command-line way for quite some time until I stumbled across your howto.

Thanks so much!

Posted by

[...] A great tutorial can be found here. [...]

Posted by

great info, thanks for the tip, did not realize you could install stuff that way.

Posted by

Thanks for the nice tutorial, this is much better than UnRar X or StuffIt. May ask where you got your wallpaper from as well? :P

Posted by

I made the wallpaper available for download. It’s the original file (15MB) with a reasonable resolution of 4883×2669 pixels. Have fun :D

Posted by

Thanks :)

Posted by

Thanks a bunch…. quite helpful!!!!!!

Posted by

Hey good stuff…keep up the good work! :)

Posted by

[...] this you need to install the CLI tool unrar from rarlabs.com and install it using the instructions here Grab em here: http://files.me.com/craig.cullum/aezqwg __________________ Follow me on Twitter [...]

Posted by

thanks you saved my life

Posted by

I have never done anything like this. I can’t get it to work at all. What is the first thing I need to type to get it to open up the desktop/downloads? nothing seems to work.

Posted by

thanks!

Posted by

I’m with jp – anyone know how to do that with multipart rars? Would be very useful for usenet users.

Posted by

@ abe & jp: Just a quick thought on my end.

Maybe it could be possible by combining the multipart filenames and their modification date. Get the last mulitpart filename and check for its modification date. This should differ at least 2 seconds or more compared to the current timestamp, meaning the download has finished.

Posted by

Goeie info Robert.
BEDANKT

Posted by

Toevoeging
Ik werk op OSX 10.6 en als ik het sudo commando uitvoer dan krijg ik de melding
spijkmaster is not in the sudoers file. This incident will be reported.

Dat betekent dus dit je commando moet uitvoeren met een account welke beheerdersrechten heeft.
Standaard is dit het 1e account welke wordt aangemaakt bij installatie.

Greetz,
Spijkmaster

Posted by

@ Spijkmaster: Graag gedaan :-)

Het klopt inderdaad dat het account waarmee je bent ingelogd moet behoren tot de groep “admin”:

~$: sudo visudo

Laat het volgende zien:

# User privilege specification
root ALL=(ALL) ALL
%admin ALL=(ALL) ALL

Uiteraard kan je met bovenstaande commando ook zelf extra gebruikers toevoegen (met beperkte root rechten). Of dit wenselijk is laat ik even in het midden ;-)

Posted by

thanks for this! very helpful!

Posted by

thank you for the detailed instructions…worked like a charm when my linux box was down.

Posted by

Hi this is nice,

but you should also check out this post:
http://stuffforlife.blogspot.com/2009/03/data-compression-in-mac-os-x-how-to.html

In this post some guy explains how to use unrar to just right click and decompress rar files… quite easy.

Thank for the post

B<est

Posted by

This is awesome, thanks! :)

Posted by

OMG THANKS SOOO MUCH. this is sucha huge help.
I didn’t know u had to install it first. Duh! lol
Thank youuuu! =D

Posted by

Complicated method of extracting rar archives; that’s one of the reasons I switched back to windows

Posted by

Thanks for the post. That was helpful!
Saludos desde Peru.

Posted by

Thanks! What a great help.

Posted by

thx a best help.XD

Posted by

Thanks everyone for this helpful post.. particularly usage of the -v flag.

Posted by

$ brew install unrar

:)

Posted by

all good, works charm. shabam!

Posted by

Instructions were clear first time, cheers

Posted by

Thanks! Saved me a ton of time. Command Line all the way!

Posted by

@derek +1 for Homebrew!

Works perfectly for me. I’m on 10.6.8.

Posted by

Coolio! Thanks for the info. Worked out perfect!

Posted by

Is it just me or are there some facts missing

Posted by

/i can type and run the command but i cannot type the password into the terminal

Posted by

Have your say

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

You must be logged in to post a comment.