Unrar Files With Terminal 10
Terminal
Hey
This post is very similar to a previous post I have done about unzipping files using Terminal. This time it is about unrar’ing files. Although this type of trick wont be used every single day for unraring files. Programs like stuffit can handle that, but this trick has one awesome feature which I will explain shortly. The first step of this trick is to download the binaries. Head over to the winrar site. Then using the following command copy it into the binary folders. These are system folders which enable you to run the unrar binary from any Terminal window.The first step is to change directory to where you downloaded and extracted the files and then type the following.
sudo mv unrar /usr/bin
or
sudo mv unrar /usr/local/bin
Either will work for using the binary. I think the second command is used if you want to use it only for your self.
The next step is to invoke the binary. Its a bit complicated. The first step as always is to change directory to the folder you .rar files are in. You could type the whole file path although I find it is easier to change directory first. Simply type the following to unrar the files you want.
unrar e file.part1.rar
You must make sure the “e” is present that tells the program to extract your files.
Probably one of the best features of this program is to extract broken archives. Broken archives are archives where you have only one (or more) of the complete set. For example if you haven’t downloaded the complete set but want to see the contents. If you try to extract these files normally, it will give an error saying incomplete archive. One simple addition to the command line and you can extract them normally. Simply type.
unrar e -kb file.part1.rar
The kb part will tell the program to keep broken files. It may give an error but the extracted file will still exist. You can view and use these files in Finder as normal. Probably one of the best tips I have found in a long while and would have saved my lots of bandwidth and time with archives I don’t need.
There are a lots more options which you can use. Normally you would use man and then unrar, to view the manual page.. This doesn’t for this program just simply type:
unrar
To get all of the help messages. This will also show you the syntax and any options associated.
This is a simple trick, which is only good for the broken file command. Still useful even if you don’t use it. You may never know when such as tip may come in handy.
If you want to take your skills with Terminal a bit further I recommend you check out the Terminal Category on this site. If you fancy reading a book there is a couple on Amazon that I regularly see mentioned and recommend, O’reilly Unix Geeks and Unix Under the Hood both are designed for Mac OS X and take Terminal further.
Where To Next?
10 Responses to “Unrar Files With Terminal”
-
1
Does it even work if i have no RAR expander installed. if yes why i can extract .rar files natively with OS X without having UNrar programs installed
Comment By MacPhobia on August 18th, at 10:58 am
-
2
You can extract files with the Mac OS X expander, but you need to download the extra program to get the extra features.
Comment By admin on August 18th, at 11:35 am
-
3
You could make this into an applescript so users could just select the file in the Finder and run the applescript from the applescript menu. The script would be something like:
tell application "Finder"
set myWin to window 1
set thePath to (POSIX path of (target of myWin as alias))
set fileList to selection as list
set listOfFiles to ""(* create a string with all the files *)
repeat with theFile in fileList
set listOfFiles to listOfFiles & " \"" & (get name of theFile) & "\""
end repeat(* no files selected? *)
if (listOfFiles is "") then
display dialog "No files selected!" buttons "Ok" default button "Ok" with icon caution
return
end ifset theCommand to "/usr/local/bin/unrar -e kb " & listOfFiles
try
do shell script "cd \"" & thePath & "\"; " & theCommand
on error errMsg number errNum
display alert "Could not make selection (" & errNum & "):" message errMsg as critical
returnend try
end tellErr, that’s assuming that ‘unrar’ will accept more than one filename if you pass it. Otherwise it’d be simpler.
Also, the /usr/bin versus /usr/local/bin isn’t for single user multi user. It’s a unix thing – files you install that don’t come with the system are usually installed in /usr/local/bin. /usr/bin is for programs that are system files. The separation is usually a bit vague though, so it really makes no difference which you put it in. All users will be able to access it either way. You’d just have to change the file path in the above script if you put your unrar in /usr/bin.
Comment By Ricky Buchanan on August 19th, at 12:55 pm
-
4
There a hundreds of ways of doing things in Terminal. Thanks for the comment Ricky.
Comment By admin on August 19th, at 1:25 pm
-
5
I had to:
sudo chmod +x /usr/bin/unrar
to use it
(goes for rar also)Comment By Nik on May 4th, at 10:05 pm
-
6
Man, OS X needs a package manager, like all other BSD distros have. Then you could just issue a quick `$ sudo pkgman install unrar` instead of doing willy-nilly */bin grafts.
I forget what FreeBSD /main calls their pacakge manager. It’s been ages since I did any sysadmin stuff on BSD boxen, though my NFSN server is FreeBSD…
But I digress.
Comment By Katie on June 1st, at 10:27 am
-
7
Neat tool. You’d want to put those binaries in /usr/local/bin though; the author should probably edit this post. In UNIX-compliant systems, /usr/local is a safe haven for files installed by the user. By user, we don’t mean the “user account” sort of user; that’d be the ~ (home) folder. Rather, /usr/local belongs to the user as distinct from the system. Mainly, it has to do with software updates; when the system updates it will happily overwrite anything is /usr/bin without any regard to the user’s files, but in no case will it touch /usr/local/bin or anything else in /usr/local.
Comment By Joel on July 31st, at 7:03 am
-
8
Thanx dude. This is the easiest how to for anything I’ve ever had to do with terminal. Props
Comment By iRage on August 3rd, at 3:36 pm
-
9
Hi, I need your help. I downloaded a file, it’s a iso file, but the download stopped at 99.83%. The files are tutorial videos to a program. I tried your method of unraring the files with “-kb” command and i get this response.. (includes the action I typed in terminal, so you can see what i did)
Manmohit:~ Manmohit$ /Users/Manmohit/Downloads/rar/unrar x -kb /Users/Manmohit/Downloads/Lynda.com.Apple.Final.Cut.Express.4.Essential.Training-QUASAR/q-lcfce4et.rar
UNRAR 3.90 freeware Copyright (c) 1993-2009 Alexander Roshal
Extracting from /Users/Manmohit/Downloads/Lynda.com.Apple.Final.Cut.Express.4.Essential.Training-QUASAR/q-lcfce4et.rar
Extracting LC_FinalCutExpress4_ET.iso 1%
ERROR: Bad archive /Users/Manmohit/Downloads/Lynda.com.Apple.Final.Cut.Express.4.Essential.Training-QUASAR/q-lcfce4et.r00Please let me now what I did wrong or did not do.
Thanks James
Comment By money on October 2nd, at 10:34 pm
-
10
Other command line can be $unrar e -r file.rar
Comment By Will on July 14th, at 9:15 am