How to convert comic book archives from .cbr/.CBR to .cbz

Many comic book files are available online in the .cbr/.CBR format, which is a RAR archive containing image files. One can easily view the images contained in the RAR archive as a document using evince by extracting the images and then creating a .cbz (Zip) archive of the images. Here is a script which converts all comic books inside a directory which are in .cbz or .CBZ format to .cbz. The script is free software and is licensed under GPL3+.

#!/bin/bash
# Author: Alon Ivtsan
# License: GPL3+

for FILE in *{.cbr,.CBR}
do
[ -e "$FILE" ] || continue
echo Converting $FILE to cbz format.
DIR="${FILE%.*}"
mkdir "$DIR";
unar ./"$FILE" -o "$DIR";
zip -r "$DIR".cbz "$DIR";
rm -r "$DIR";
#Remove or comment out this line if you want to keep cbr files
#rm "$FILE";
echo Conversion of $FILE successful!
done 

In order to use the script first install the packages zip, unzip and unar

$ sudo aptitude install unar unzip zip

and then just copy the script into a file called "cbrtocbz.sh" in a folder containing .cbz and .CBZ files, and run it using the command

$ ./cbrtocbz.sh

If you want the script to also delete the .cbr and .CBR files just remove the symbol # from the line "#rm "$FILE";".

Revisions

07/21/2014 - 04:48
aloniv