Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application. You don't need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type 'em out!
You’ve probably heard of ZIP files, and may have heard of TAR files, but RAR files are another compression technique with added benefits that you can use to send your files over the Internet or store on a disc. The advantages of RAR over ZIP is that RAR files can store the full file permissions, can be split into multiple files for easier transmission or storage, and have improved error handling and data redundancy in case your RAR file arrives broken due to transmission errors or bad sectors. Many users don’t know how to deal with RAR files, however, so we’ll show you how to extract their contents in this Terminal 101.
The first step to using RAR files on your Mac is to install the unrar package from Homebrew or MacPorts. To do this, type in the following command if you’re using Homebrew:
brew install unrar
If you’re using MacPorts on your system, then type in the following command to install the unrar program onto your Mac:
sudo port install unrar
You’ll be required to enter your administrator password if you’re using MacPorts to complete the installation.
Listing contents inside the RAR file
Not sure if you wish to extract the contents of the downloaded RAR file? There’s an easy way that you can check to see what the contents of the file look like before you go through the extraction process. To do this, type the following command into the Terminal:
unrar l file.rar
Replace “file.rar” with the actual name of your RAR file. When you do this, you will get a listing of the files contained inside of the RAR package. It will list the file name, size, compression ratio, date, time, and permission attributes.
Testing the RAR file
If you believe that a file inside of your RAR file may be damaged, then you can test it using the unrar utility. To do this, type in the following command:
unrar t file.rar
Replace “file.rar” with the actual name of you RAR file. When this command is run, you will see the file listing of the contents of the RAR file, and an “OK” beside of the files that are verified as having passed the file integrity check.
Unrar-ing the file
To unrar your RAR file (i.e. to extract the contents of the RAR file), we’ll use the following command:
unrar x file.rar
Replace “file.rar” with the path and filename of the RAR file that you will be extracting, and then press the enter key. The contents of the RAR file will be extracted to your current working directory. If you wish to extract the contents of the file to a particular directory, use this command instead:
unrar e file.rar /pathToExtractTo
Replace “file.rar” with the path and filename of the RAR file that you wish to extract; and, replace “ /pathToExtractTo” with the path that you wish to extract the contents to.
For instance, if we had a file on our Desktop called “Sample.rar” and we wished to extract the contents to a folder on the Desktop called “MyFiles,” we could use the following command:
unrar e /Desktop/Sample.rar /Desktop/MyFiles/
This would extract the contents to the MyFiles folder on the desktop. If the MyFiles directory doesn’t already exist, the unrar utility will create it for you automatically and place the files inside.
It is rare that you run into RAR files online, but in the event that you do, this unrar utility will come handy and allow you to handle the contents of the RAR file with ease.
Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author on Twitter.