#!/bin/bash
pwd=`pwd`
find ${pwd} -type f -name *.rar |
while read "file"
do
directory=`dirname ${file}`
filename=`basename ${file}`
let number=${#filename}-2
cd ${directory}
unrar x ${filename}
if [ $? -eq 0 ]; then
rm ${filename:0:${number}}*
else
echo ERROR: unrar failed on $file
fi
cd ${pwd}
done