Ever needed a script that automatically extracts all rar archives in a directory and subdirectories, unrar them into their respective directories and then delete the archive files, but only if the extraction was successful? Well in that case, I wrote this little bash script today:
#!/bin/bash
if [ -n "$1" ]
then
echo "Unraring from $1"
find $1 -type f -name '*.part01.rar' -execdir rar x -y -o- {} \;
find $1 -type f -name '*.part001.rar' -execdir rar x -y -o- {} \;
find $1 -type f -name '*.rar' -execdir rar x -y -o- {} \;
fi
It takes the path of the folder you want to scan as argument: unrarscript.sh /path/to/folder
Edit Jan 31 2011: It seems the if statements checking if the extraction failed or not only checks if last extraction was successful. For it to work correctly the unlink should be nested inside the finds. I have not yet made any corrections to the script, but be aware of this weakness.
Edit Nov 11 2011: Just removed the unlink part as it wasn’t working properly anyway.








