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


2 Answers 2


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 Terminal.app 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 http://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash
    # 1st answer
    filename=$(basename "$file")

    # Temp folder in the loop

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

    # unzip -d folder/extract/to fileToExtract.zip
    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 terminal.app


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.

  • 1
    If every novice bash programmer would write code of this quality, the world of scripts would be a better place! Well done.
    – nohillside
    Aug 15, 2012 at 18:50
  • Thanks, that is my first bash script ever ^^. I Wrote alot of comments for learning purpose
    – GabLeRoux
    Aug 15, 2012 at 18:53
  • 1
    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.
    – Lri
    Aug 15, 2012 at 19:15
  • I don't think you can save to /bin anymore, so you should use /usr/local/bin instead.
    – benwiggy
    Jan 26, 2022 at 10:42

Here's a simpler script like the one posted by GabLeRoux. rar can be downloaded from from http://www.rarlab.com/download.htm.


for f in ~/Desktop/*.zip; do
    unzip "$f" -d $d
    cd "$d"
    rm -rf __MACOSX
    ~/bin/rar a "${f%zip}rar" *
    rm -r "$d"
  • Err, there is a cd .. missing somewhere :-)
    – nohillside
    Aug 15, 2012 at 18:51
  • What do you mean? The glob expression at the start is ~/Desktop/*.zip just for testing.
    – Lri
    Aug 15, 2012 at 18:58
  • You cd into $d but where do you get out of the directory again?
    – nohillside
    Aug 15, 2012 at 19:25
  • 1
    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".
    – Lri
    Aug 15, 2012 at 19:42
  • Join me in chat.stackexchange.com/rooms/4519/room-for-patrix-and-lri to discuss further
    – nohillside
    Aug 15, 2012 at 19:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .