Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Any suggestion of how to convert tens of zip files to rar format? App or command line tool are welcome.

share|improve this question
Why do you want to do that? – lhf Aug 15 '12 at 12:07
There is a comic viewer which works well with .rar files but not .zip files. – ohho Aug 16 '12 at 4:48
up vote 5 down vote accepted

What you could do is making a little batch file that would use RAR, a shareware command line utility for mac (I did not find any free rar command line utility, but RAR is available as a trial).

Installing rar command

To install RAR into your terminal, simply copy rar and unrar into your bin folder.

To get access to the bin directory, open and type

open ­/bin

The Windows version of RAR allows to "convert" zip archive into rar archive in tools, but the mac version doesn't seem to have this feature. The solution would be to unzip each of the files into separate folders and then to RAR content of those folders right away.

The Solution

# shell script that will convert zip files into rar files
# Require RAR for Mac os x to be placed in bin folder

# Working directory, use ~ for home folder shortcut :)

# Temp directory that will be used for zip files manipulation
# Will prevent loop from raring other folders ;)

# Target Directory is where you want the rar files to go after the process

# Let's create the directories
mkdir "${TempDirectory}"
mkdir "${TargetDirectory}"

# Will loop into WorkingDirectory and unzip each .zip files
for file in "${WorkingDirectory}"/*.zip
    # Get file name
    # See
    # 1st answer
    filename=$(basename "$file")

    # Temp folder in the loop

    # Create folders to rar later
    mkdir "${tempFolderToRar}"

    # unzip -d folder/extract/to
    unzip -d "${TempDirectory}"/"${filename}" "${file}"

    # rar all the files in tempFolderToRar into the target
    rar a "${TargetDirectory}"/"${filename}".rar "${tempFolderToRar}"

# Optionnaly, delete temp directory if different from target
if [ "${TempDirectory}" != "${TargetDirectory}" ]
    rm -r "${TempDirectory}"

Save this to a file with no extension, be sure to set the good paths in the first variables and it should work fine running it in


Well, It worked for me.

Note: this script is not perfect. Maybe there's a better way, but it works ;) that was one of my first shell script, would probably be better with parameters, or go with python ;)

Hope it helps.

share|improve this answer
If every novice bash programmer would write code of this quality, the world of scripts would be a better place! Well done. – patrix Aug 15 '12 at 18:50
Thanks, that is my first bash script ever ^^. I Wrote alot of comments for learning purpose – GabLeRoux Aug 15 '12 at 18:53
rm -r ${TempDirectory}, mkdir ${TempDirectory}, and mkdir ${TargetDirectory} should also be double-quoted. You should probably use something like mktemp -td or mkdir /tmp/$(uuidgen) for creating the temporary directory. The files in the rar archives are extracted to $PWD/$TempDirectory. – user495470 Aug 15 '12 at 19:15

Here's a simpler script like the one posted by GabLeRoux. rar can be downloaded from from


for f in ~/Desktop/*.zip; do
    unzip "$f" -d $d
    cd "$d"
    rm -rf __MACOSX
    ~/bin/rar a "${f%zip}rar" *
    rm -r "$d"
share|improve this answer
Err, there is a cd .. missing somewhere :-) – patrix Aug 15 '12 at 18:51
What do you mean? The glob expression at the start is ~/Desktop/*.zip just for testing. – user495470 Aug 15 '12 at 18:58
You cd into $d but where do you get out of the directory again? – patrix Aug 15 '12 at 19:25
The PWD at the end wouldn't matter unless the script does something after converting the archives. It could be kept by running the script in a subshell with ( ) or with something like oldpdw="$PWD" ... cd "$oldpwd". – user495470 Aug 15 '12 at 19:42
Join me in to discuss further – patrix Aug 15 '12 at 19:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.