SCRIPTS TO EXTRACT AND ORGANIZE YOUR RAR FILES
#############################################
#############################################

UPDATE 04-28-2015: latest scripts for unrar (and also unzip version) located over here: unrar123 & unzip scripts


Good if you torrent. Not that I do, I dont even know what that is.

This works great on rar files that are split into volumes as well (meaning rar files that are split into many rar files, such as rar, r01, r02, etc).

INTERESTING NOTE IF YOU DONT WANT TO EXTRACT THEM: you can watch RARed up movies (even if multiple rar files) from VLC. Also you can mount RAR files as mount points with linux. Or you can pull individual files from the RAR files.

Here I will show you how to extract multiple rar files scattered in multiple directories. Kind of like the way your folders look after doing some downloads.

STEP1)

Get the correct rar tool first

DONT USE unrar-free – the best rar tool you have to download and install using below method

Go here: http://www.rarlab.com/download.htm and find the latest linux version (one thats 64bit or the none 64 bit one). Im going to use the 64 bit one.

At my time the latest one is:http://www.rarlab.com/rar/rarlinux-x64-5.1.0.tar.gz

cd /root
mkdir src
wget http://www.rarlab.com/rar/rarlinux-x64-5.1.0.tar.gz
tar xzf rarlinux*
cd rar

NOTE: the unrar file should just work right there without compiling. ./unrar to use it. But lets install it (meaning copy its contents to $PATH type of directories, using its built in install)

make install

NOTE: if above fails type “apt-get upate && apt-get install build-essential”

NOTE: to uninstall look at the makefile and look at the files and the locations they get copied to, then just erase those files manually. these files are so small and insignificant that uninstalling shouldnt really be that important to you. the install of unrar shouldnt hurt a soul (besides that of unrar-free)

NOTE: if you accidentaly do already have unrar-free. Uninstall it like so: apt-get remove unrar-free && hash -r  the hash -r part unties unrar from unrar-free’s unrar file

STEP2)

Check out how many rar files your dealing with (we dont care about the .rXX ones, just the .rar, so we can see how many rar sets we are dealing with)

Now we can go on to extracting

This method will extract each rar file in its own folder. It will find multiple rar files such as .r01 and etc automatically.

cd /downloads
find -type rar | grep rar | nl

NOTE: in examples below my SOURCE variable is the location where all of the rars are at (and I change it up from /downloads to other names, because I was doing my own testing and my rar files arent in a location called /downloads)

The above tells you how many rar files there are to extract (the nl will number them out)

STEP3) Pick a script and run it (3 scripts below to choose from. My favorite is script 2 or 3)

##########################################
SCRIPT1 – mass rar extract to original folders (messy)
##########################################

pro: less folders
con: rars mixed with extracted stuff

The below script will extract each rar file into its current directory (the rars will make whatever subdirectories they need to make – which ever ones they contain of course).

Here is a visual example of what it will do

Imagine the following rar files:

/Downloads/game1/<rar here and extracts here>
/Downloads/Movies/Movie1/<rar here and extracts here>
/Downloads/Movies/Movie2/<rar here and extracts here>
/Downloads/Movies/Videos/Homemovies/<rar here and extracts here>
/Downloads/Movies/Videos/Tvshows/<rar here and extracts here>
/Downloads/Movies/Videos/Tvshows/Show1/<rar here and extracts here>
/Downloads/Movies/Videos/Tvshows/Show1/Episode1/<rar here and extracts here>
/Downloads/Movies/Videos/Tvshows/Show1/Episode2/<rar here and extracts here>
/Downloads/Movies/Videos/Tvshows/Show2/<rar here and extracts here>

In above example I would choose
SOURCE=/Downloads

NOTE: you will need to get rid of the rar files afterwards for cleanup

NOTE: Don’t forget to set the SOURCE variable (or comment the SOURCE= line and the cd $source line and just copy paste below script into your bash, to unrar recursively in the current working directory)

#!/bin/bash
# WHAT THIS DOES:
# The below script will extract each rar file into its current directory (the rars will make whatever subdirectories they need to make - which ever ones they contain of course).
# WHAT TO DO:
# 1. fill out SOURCE variable (thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation)
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=/data/Main/DownloadsZ
OVERWRITE="-o+"
# OVERWRITE="-o-" 
# OVERWRITE=" "
cd $SOURCE
OLDIFS=$IFS
IFS=$'\n'
for i in `find -type f | grep rar$`; do 
echo "### --------[`date +%D-%T`][`date +%s`]--------";
FILEFULLPATH=`readlink -f $i`;
FULLDIR=`dirname $FILEFULLPATH`;
echo "### EXTRACTING ${i} TO ${FULLDIR}:"
echo "### unrar x $OVERWRITE ${i} ${FULLDIR}"
unrar x $OVERWRITE "${i}" "${FULLDIR}";
done;
IFS=$OLDIFS)

##############################################
SCRIPT2 – mass rar extract to original folder, but also make _extracted folder in there
##############################################

pro: more organized, everything is together
con: annoying extra _extracted folder

The below script will extract each rar file into its current directory within a special _extracted folder in each directory for extra organization (the rars will make whatever subdirectories they need to make – which ever ones they contain of course).

Imagine the following rar files:

/Downloads/game1/<rar>
/Downloads/Movies/Movie1/<rars>
/Downloads/Movies/Movie2/<rars>
/Downloads/Movies/Videos/Homemovies/<rars>
/Downloads/Movies/Videos/Tvshows/<rars>
/Downloads/Movies/Videos/Tvshows/Show1/<rars>
/Downloads/Movies/Videos/Tvshows/Show1/Episode1/<rars>
/Downloads/Movies/Videos/Tvshows/Show1/Episode2/<rars>
/Downloads/Movies/Videos/Tvshows/Show2/<rars>

It will extract like so:

/Downloads/game1/_extracted/%
/Downloads/Movies/Movie1/_extracted/%
/Downloads/Movies/Movie2/_extracted/%
/Downloads/Movies/Videos/Homemovies/_extracted/%
/Downloads/Movies/Videos/Tvshows/_extracted/%
/Downloads/Movies/Videos/Tvshows/Show1/_extracted/%
/Downloads/Movies/Videos/Tvshows/Show1/Episode1/_extracted/%
/Downloads/Movies/Videos/Tvshows/Show1/Episode2/_extracted/%
/Downloads/Movies/Videos/Tvshows/Show2/_extracted/%

The % represents the extracted rar content, without any of the rar files

In above example I would choose
SOURCE=/Downloads

NOTE: Don’t forget to set the SOURCE variable (or comment the SOURCE= line and the cd $source line and just copy paste below script into your bash, to unrar recursively in the current working directory)

#!/bin/bash
# WHAT THIS DOES:
# The below script will extract each rar file into its current directory within a special _extracted folder in each directory for extra organization (the rars will make whatever subdirectories they need to make - which ever ones they contain of course).
# WHAT TO DO:
# 1. fill out SOURCE variable (thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation)
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=/data/Main/DownloadsY
OVERWRITE="-o+"
# OVERWRITE="-o-" 
# OVERWRITE=" "
cd $SOURCE
OLDIFS=$IFS
IFS=$'\n'
for i in `find -type f | grep rar$`; do 
echo "### --------[`date +%D-%T`][`date +%s`]--------";
FILEFULLPATH=`readlink -f $i`;
FULLDIR=`dirname $FILEFULLPATH`;
mkdir -p ${FULLDIR}/_extracted 2> /dev/null
echo "### EXTRACTING ${i} TO ${FULLDIR}/_extracted:"
echo "### unrar x $OVERWRITE ${i} ${FULLDIR}/_extracted"
unrar x $OVERWRITE "${i}" "${FULLDIR}/_extracted";
done;
IFS=$OLDIFS)

####################################################
SCRIPT3 – mass rar extract to segregated folder keeping directory structure (clean)
####################################################

pro: cleaners, looks betters. rars in one folder set, extracted stuff in another
con: more foldres

For the best seperation of extracted and none extracted stuff. Check out this method. It will extract all rar files into /extractdir but maintain the name of the paths. So its like making a directory tree copy except now all of the rar files will be in /downloads, and the /extractdir will have all of the extracted stuff

Here is a visual example of what it will do

Imagine the following rar files:

/Downloads/game1/<rar>
/Downloads/Movies/Movie1/<rars>
/Downloads/Movies/Movie2/<rars>
/Downloads/Movies/Videos/Homemovies/<rars>
/Downloads/Movies/Videos/Tvshows/<rars>
/Downloads/Movies/Videos/Tvshows/Show1/<rars>
/Downloads/Movies/Videos/Tvshows/Show1/Episode1/<rars>
/Downloads/Movies/Videos/Tvshows/Show1/Episode2/<rars>
/Downloads/Movies/Videos/Tvshows/Show2/<rars>

And it will extract to this:

/Downloads-Extracted/game1/%
/Downloads-Extracted/Movies/Movie1/%
/Downloads-Extracted/Movies/Movie2/%
/Downloads-Extracted/Movies/Videos/Homemovies/%
/Downloads-Extracted/Movies/Videos/Tvshows/%
/Downloads-Extracted/Movies/Videos/Tvshows/Show1/%
/Downloads-Extracted/Movies/Videos/Tvshows/Show1/Episode1/%
/Downloads-Extracted/Movies/Videos/Tvshows/Show1/Episode2/%
/Downloads-Extracted/Movies/Videos/Tvshows/Show2/%

The % represents the extracted rar content, without any of the rar files

In above example I would choose
SOURCE=/Downloads
DESTINATION=/Downloads-Extracted/

NOTE: Don’t forget to set the SOURCE variable (or comment the SOURCE= line and the cd $source line and just copy paste below script into your bash, to unrar recursively in the current working directory)

#!/bin/bash
# WHAT THIS DOES:
# this will take a folder structure with lots of rars, and copy it to another folder set, but extract all the rars nicely
# WHAT TO DO:
# 1. fill out SOURCE & DESTINATION variable
# note about the source: thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation
# note about the destination: this will only copy out the folder structure as is for rar files, then it will also make the correct folder structure that the rar files contained within them. When typing the destination folder, it doesnt matter if it ends in a / or doesnt (same goes for source)
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# make sure that the destination folder is not in the source folder
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=/data/Main/DownloadsX
DESTINATION=/data/Main/DownloadsXE/
OVERWRITE="-o+"
# OVERWRITE="-o-" 
# OVERWRITE=" "
OLDIFS=$IFS
IFS=$'\n'
cd $SOURCE
mkdir -p $DESTINATION 2> /dev/null
for i in `find -type f | grep "rar$"`; do 
echo "### --------[`date +%D-%T`][`date +%s`]--------";
FILEFULLPATH=`readlink -f $i`;
RELATIVEDIR=`dirname $i`;
NEWRDIR=${RELATIVEDIR#.}
echo "### EXTRACTING ${i} TO ${NEWRDIR}:"
mkdir -p ${DESTINATION}${NEWRDIR} 2> /dev/null
echo "### unrar x ${FILEFULLPATH} ${DESTINATION}${NEWRDIR}";
unrar x $OVERWRITE "${FILEFULLPATH}" "${DESTINATION}${NEWRDIR}"
done;
IFS=$OLDIFS)

  ALL SCRIPTS MADE INTO EXECUTABLE SCRIPT

– the above are more of copy pasteables (where you edit the source and destination)

– the below are more of scripts, that are run from command line. They will look for rar files from current folder down recursively. Only the 3rd script needs an argument (to tell it where to extract the folders)

– keep in mind each of the 3 scripts does unrar into different folder differently (pick which ever one you need for the job). I can find it that at different times different ones are useful.

SCRIPT: unrar1samedir.sh
################################

#!/bin/bash
# WHAT THIS DOES:
# The below script will extract each rar file into its current directory (the rars will make whatever subdirectories they need to make - which ever ones they contain of course).
# WHAT TO DO:
# 1. fill out SOURCE variable (thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation) or run as script
# - if running as script it will start looking at files from the current folder, not where the script is
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=`pwd`
echo "$0 STARTING RECURSIVE UNRAR TO SAME DIRS AS THE RAR FILES ARE AT, STARTING AT $SOURCE"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
cd $SOURCE
OLDIFS=$IFS
IFS=$'\n'
for i in `find -type f | grep rar$`; do
echo "### --------[`date +%D-%T`][`date +%s`]--------";
FILEFULLPATH=`readlink -f $i`;
FULLDIR=`dirname $FILEFULLPATH`;
echo "### EXTRACTING ${i} TO ${FULLDIR}:"
echo "### unrar x $OVERWRITE ${i} ${FULLDIR}"
unrar x $OVERWRITE "${i}" "${FULLDIR}";
done;
IFS=$OLDIFS)

SCRIPT: unrar2extracted.sh
################################

#!/bin/bash
# WHAT THIS DOES:
# The below script will extract each rar file into its current directory within a special _extracted folder in each directory for extra organization (the rars will make whatever subdirectories they need to make - which ever ones they contain of course).
# WHAT TO DO:
# 1. fill out SOURCE variable (thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation). Or run it as script.
# - if run as script, it will look for files in current shell folder, not where the script resides (unless thats where your current folder is)
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=`pwd`
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
echo "$0 STARTING RECURSIVE UNRAR & CREATING _extracted FOLDERS IN SAME FOLDER AS RAR FILES, STARTING HERE: $SOURCE"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
cd $SOURCE
OLDIFS=$IFS
IFS=$'\n'
for i in `find -type f | grep rar$`; do
echo "### --------[`date +%D-%T`][`date +%s`]--------";
FILEFULLPATH=`readlink -f $i`;
FULLDIR=`dirname $FILEFULLPATH`;
mkdir -p ${FULLDIR}/_extracted 2> /dev/null
echo "### EXTRACTING ${i} TO ${FULLDIR}/_extracted:"
echo "### unrar x $OVERWRITE ${i} ${FULLDIR}/_extracted"
unrar x $OVERWRITE "${i}" "${FULLDIR}/_extracted";
done;
IFS=$OLDIFS)

SCRIPT: unrar3todir.sh
################################

#!/bin/bash
# usage: $0 <diff directory to extract to>
# WHAT THIS DOES:
# this will take a folder structure with lots of rars, and copy it to another folder set, but extract all the rars nicely
# WHAT TO DO:
# 1. fill out SOURCE & DESTINATION variable
# or 1. Run as script "usage: unrar3todir.sh <directory>" - not it will extract every rar file recursively from current folder (not where script is, but where you are in the shell) to the dest folder specified
# note about the source: thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation
# note about the destination: this will only copy out the folder structure as is for rar files, then it will also make the correct folder structure that the rar files contained within them. When typing the destination folder, it doesnt matter if it ends in a / or doesnt (same goes for source)
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# make sure that the destination folder is not in the source folder
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=`pwd`
DESTINATION=$1
if [ -z $DESTINATION ]; then echo -e "UNRAR RECURSIVELY TO DIFFERENT DIRS\nusage: $0 <directory to extract to>"; exit 1; fi
echo "$0 IS STARTING RECURSIVE UNRAR OF $SOURCE TO $DESTINATION"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
OLDIFS=$IFS
IFS=$'\n'
cd $SOURCE
mkdir -p $DESTINATION 2> /dev/null
for i in `find -type f | grep "rar$"`; do
echo "### --------[`date +%D-%T`][`date +%s`]--------";
FILEFULLPATH=`readlink -f $i`;
RELATIVEDIR=`dirname $i`;
NEWRDIR=${RELATIVEDIR#.}
echo "### EXTRACTING ${i} TO ${NEWRDIR}:"
mkdir -p ${DESTINATION}${NEWRDIR} 2> /dev/null
echo "### unrar x ${FILEFULLPATH} ${DESTINATION}${NEWRDIR}";
unrar x $OVERWRITE "${FILEFULLPATH}" "${DESTINATION}${NEWRDIR}"
done;
IFS=$OLDIFS)

 

LATEST UNRAR SCRIPTS BELOW

Update happened on 2015-01-18: latest versions of all 3 unrar scripts are below (actually now there are 6 unrar scripts, each one has an extra variation, more info below) – please read the comments below to see the new changes and details about all of the scripts. The scripts have went under many improvements & changes from the above scripts in the article, to make them better to use and fix errors. Also shows stats.

SIDENOTE ABOUT THE SCRIPTS THAT DELETE THE RARS AFTER SUCCESSFUL EXTRACTION: Use unrar2extracted-delete-rars.sh rather that the unrar1 or 3 version of *delete-rars.sh. unrar2 algorithm just handles it better than unrar1 and unrar3 when deleting the rar files after successful deletion – more on it below in the comments.

##########################################
# UNRAR TOOLS - unrar1 unrar2 and unrar3 #
##########################################

# date: 2015-01-18

# this is the latest source code for all my unrar scripts 

# UPDATE ON: 2015-01-18 night: added stats.

# UPDATE ON: 2015-01-18 morning: added a variation for the 3 rar tools, the current files are now this:
# * unrar1samedir.sh - unrar everything recursively to same directory as where the current rar file is
# * unrar1samedir-delete-rars.sh - unrar everything recursively to the same directory as where the rar file is (Delete the rar and its associated split files, a.k.a. volumes with it)
# * unrar2extracted.sh - unrar everything recursively to a new _extracted directory relative to where the rar file is
# * unrar2extracted-delete-rars.sh - unrar everything recursively to a new _extracted directory relative to where the rar file is (delete the rar & its associated split file/volume files)
# * unrar3todir.sh - unrar everything recursively but a completely different directory tree while maintaining the directory tree of the source
# * unrar3todir-delete-rars.sh - unrar everything recursively but a completely different directory tree while maintaining the directory tree of the source (delete the rar & its associated split file/volume files)
# SIDENOTE: I know its best to make a single script with these options, but i havent gotten to it yet
# SIDENOTE ABOUT unrar2 and unrar2extract-delete-rars.sh: its best to use unrar2 if your looking to delete the rar files afterwards. Why? well its complicated but when you have rar files that are split unusually like part01.rar and part02.rar rather than rar & r01 & r02, then the script just doesnt work as well. So its best to use unrar2extracted-delete-rar.sh. Even then when you use it, it will not delete all of the rars when the following files are encountered part01.rar and part02.rar, so you will need to search your directories for those files - then if you try to extract those files after they will fail because a part of those volumes have been deleted (but dont worry the extracted directory actually contains the full correct contents, because the first extraction usually doesnt grab the first rar file of the bunch it could grab like part05.rar which will extract everything from part01.rar to lets say its final piece of part08.rar, but when deleting "rar l v" which lists the volumes/splits will only mention part05,06,07 and 08 - so part 01 thru 04 survive, after that part01 thru part04 try to get extracted but they fail - failed rars dont get deleted by my algorithm - because they could be failed due to not being downloaded all the way yet.). So I thought it out much and unrar2extracted-delete-rars.sh is the best way to go if you want to delete the rar files afterwards. If you dont want to delete the rar files afterwards then you have nothing to worry about, just use any unrar1,2 or 3. I just personally use unrar2 the most as it seems the safest.

# UPDATE ON 2014-09-26
# * fixed bugs for folders with spaces
# * creates '.extracted' file if file has been extracted with unrar1,2,3. the file will have information on how and where it was extracted. it will not allow extraction of same file again. To allow for the extraction delete the '.extracted' file (command will be given on how to delete the '.extracted' file if the extraction fails due to the existence of a '.extracted' file)
# * if your not using bash 4 or newer then |& will not work (its used twice in every script). Just change every |& to a simple | and it will work.
# * To delete all .extracted files recursively:
# rm -i `find | grep ".extracted$"`
# * Or delete without asking:
# rm -f `find | grep ".extracted$"`

##### -- SOURCE CODE BEGINS BELOW -- #####

=========================
unrar1samedir.sh
=========================
#!/bin/bash
# WHAT THIS DOES:
# The below script will extract each rar file into its current directory (the rars will make whatever subdirectories they need to make - which ever ones they contain of course).
# WHAT TO DO:
# 1. fill out SOURCE variable (thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation) or run as script
# - if running as script it will start looking at files from the current folder, not where the script is
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=`pwd`
echo "$0 STARTING RECURSIVE UNRAR TO SAME DIRS AS THE RAR FILES ARE AT, STARTING AT $SOURCE"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
cd "${SOURCE}"
OLDIFS=$IFS
IFS=$'\n'
COUNT=0; COUNT1=0; COUNT2=0; COUNT3=0; COUNT4=0;
echo "#### --[$0][$$][`date +%D-%T`/`date +%s`]-- ####" > /var/log/unrar123.brief
for i in `find -type f | grep \.rar$`; do
	COUNT0=$((COUNT0+1));
	echo "### --------[`date +%D-%T`][`date +%s`]--------";
	FILEFULLPATH=`readlink -f "${i}"`;
	FULLDIR=`dirname "${FILEFULLPATH}"`;
	DSTDIR="${FULLDIR}";
	echo "### ${COUNT0}. EXTRACTING ${i} TO ${DSTDIR}:"
	echo "### unrar x $OVERWRITE ${i} ${DSTDIR}"
	EXTRACTED1="${i}.extracted"
	if [ -f "${EXTRACTED1}" ]; then
	   TMPW="PREVIOUSLY EXTRACTED"
	   COUNT1=$((COUNT1+1));
	   echo "[`date`] [`date +%s`] Attempted $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   echo "    File has already been extracted, to try again: 'rm $EXTRACTED1'"
	   cat "${EXTRACTED1}" | grep . | awk '{print "*       " $0;}'
	   echo "    *** $COUNT1 non-extractable rar files ($COUNT0 total rars scanned)"
	else
	   COUNT2=$((COUNT2+1));
	   echo "    *** $COUNT2 extractable rar files ($COUNT0 total rars scanned)"
	   ### unrar x $OVERWRITE "${i}" "${FULLDIR}" |& grep . |& awk '{print "*    " $0;}' && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   ### STATUS="FAIL"
	   STATUSFILE=/tmp/unrar1status-`date +%s`-`echo $$`
	   echo "FAIL" > $STATUSFILE
	   (unrar x $OVERWRITE "${i}" "${DSTDIR}" && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}" && echo "SUCCESS" > $STATUSFILE) |& grep . |& awk '{print "*    " $0;}'
	   echo "$0|`date`/`date +%s`|`cat $STATUSFILE`|$SOURCE|$i" >> /var/log/unrar123.log
	   if grep -q "^SUCCESS$" "$STATUSFILE"; then
	        TMPW="EXTRACTION SUCCESSFUL"
			COUNT3=$((COUNT3+1));
			echo "   *** Extracted Succesfully - along with $COUNT3 out of $COUNT2 extractable rars"
	   else
	        TMPW="EXTRACTION FAILED"
			COUNT4=$((COUNT4+1));
			echo "   *** Failed to Extract - along with $COUNT4 out of $COUNT2 extractable rars"
	   fi
	   rm $STATUSFILE
	fi
	echo "   *** TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" | tee -a /var/log/unrar123.log
	echo "* ${FILEFULLPATH} : ${TMPW}" >> /var/log/unrar123.brief

done;
echo "* TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" >> /var/log/unrar123.brief
cat /var/log/unrar123.brief >> /var/log/unrar123.allbrief
IFS=$OLDIFS)

=========================
unrar1samedir-delete-rars.sh
=========================
#!/bin/bash
# WHAT THIS DOES:
# The below script will extract each rar file into its current directory (the rars will make whatever subdirectories they need to make - which ever ones they contain of course).
# this will also delete the rar files after successful extraction (including the split/volume files)
# WHAT TO DO:
# 1. fill out SOURCE variable (thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation) or run as script
# - if running as script it will start looking at files from the current folder, not where the script is
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=`pwd`
echo "$0 STARTING RECURSIVE UNRAR TO SAME DIRS AS THE RAR FILES ARE AT, STARTING AT $SOURCE"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
cd "${SOURCE}"
OLDIFS=$IFS
IFS=$'\n'
COUNT=0; COUNT1=0; COUNT2=0; COUNT3=0; COUNT4=0;
echo "#### --[$0][$$][`date +%D-%T`/`date +%s`]-- ####" > /var/log/unrar123.brief
for i in `find -type f | grep \.rar$`; do
	COUNT0=$((COUNT0+1));
	echo "### --------[`date +%D-%T`][`date +%s`]--------";
	FILEFULLPATH=`readlink -f "${i}"`;
	FULLDIR=`dirname "${FILEFULLPATH}"`; ## Since extracting to the same directory DSTDIR is the same as FULLDIR
	DSTDIR="${FULLDIR}";
	echo "### ${COUNT0}. EXTRACTING ${i} TO ${DSTDIR}:"
	echo "### unrar x $OVERWRITE ${i} ${DSTDIR}"
	EXTRACTED1="${i}.extracted"
	if [ -f "${EXTRACTED1}" ]; then
	   TMPW="PREVIOUSLY EXTRACTED"
	   COUNT1=$((COUNT1+1));
	   echo "[`date`] [`date +%s`] Attempted $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   echo "    File has already been extracted, to try again: 'rm $EXTRACTED1'"
	   cat "${EXTRACTED1}" | grep . | awk '{print "*       " $0;}'
	   echo "    *** $COUNT1 non-extractable rar files ($COUNT0 total rars scanned)"
	else
	   TMPW="EXTRACTION SUCCESSFUL"
	   COUNT2=$((COUNT2+1));
	   echo "    *** $COUNT2 extractable rar files ($COUNT0 total rars scanned)"
	   ### unrar x $OVERWRITE "${i}" "${FULLDIR}" |& grep . |& awk '{print "*    " $0;}' && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   ### STATUS="FAIL"
	   STATUSFILE=/tmp/unrar1status-`date +%s`-`echo $$`
	   echo "FAIL" > $STATUSFILE
	   (unrar x $OVERWRITE "${i}" "${DSTDIR}" && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}" && echo "SUCCESS" > $STATUSFILE) |& grep . |& awk '{print "*    " $0;}'
	   echo "$0|`date`/`date +%s`|`cat $STATUSFILE`|$SOURCE|$i" >> /var/log/unrar123.log
	   ### added this to delete rars - start ###
	   if grep -q "^SUCCESS$" "$STATUSFILE"; then
	       TMPW="EXTRACTION FAILED"
	       COUNT3=$((COUNT3+1));
		   echo "   *** Extracted Succesfully - along with $COUNT3 out of $COUNT2 extractable rars"
		   VV=0
		   for j in `unrar la -v "${FILEFULLPATH}"  | awk '/^Archive:/{$1="";print $0}' | sed 's/^[ \t]*//;s/[ \t]*$//'`; do
			   VV=$((VV+1))
			   DELETEVOL="$j"
			   ## DELETEVOLFULLPATH="$FULLDIR/$j"
			   (echo -n "+ ${VV} SUCCESSFUL UNRAR -> Deleting rar volume: ${DELETEVOL}: "
			   rm -f "${DELETEVOL}" && echo "deleted!" || echo "delete failed!") |  tee -a "${EXTRACTED1}"
		   done
	   else
	       COUNT4=$((COUNT4+1));
		   echo "   *** Failed to Extract - along with $COUNT4 out of $COUNT2 extractable rars"
		   echo "+ NOT SUCCESSFUL UNRAR -> Not deleting rar volume[s]"
	   fi

	   ### added this to delete rars - end ###
	   # delete the status file, so as to not fill up the /tmp folder
	   rm $STATUSFILE
	fi
	echo "   *** TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" | tee -a /var/log/unrar123.log
    echo "* ${FILEFULLPATH} : ${TMPW}" >> /var/log/unrar123.brief
done;
echo "* TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" >> /var/log/unrar123.brief
cat /var/log/unrar123.brief >> /var/log/unrar123.allbrief
IFS=$OLDIFS)

=========================
unrar2extracted.sh
=========================
#!/bin/bash
# WHAT THIS DOES:
# The below script will extract each rar file into its current directory within a special _extracted folder in each directory for extra organization (the rars will make whatever subdirectories they need to make - which ever ones they contain of course).
# WHAT TO DO:
# 1. fill out SOURCE variable (thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation). Or run it as script.
# - if run as script, it will look for files in current shell folder, not where the script resides (unless thats where your current folder is)
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE="`pwd`"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
echo "$0 STARTING RECURSIVE UNRAR & CREATING _extracted FOLDERS IN SAME FOLDER AS RAR FILES, STARTING HERE: $SOURCE"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
cd "${SOURCE}"
OLDIFS=$IFS
IFS=$'\n'
COUNT=0; COUNT1=0; COUNT2=0; COUNT3=0; COUNT4=0;
echo "#### --[$0][$$][`date +%D-%T`/`date +%s`]-- ####" > /var/log/unrar123.brief
for i in `find -type f | grep \.rar$`; do
    COUNT0=$((COUNT0+1));
	echo "### --------[`date +%D-%T`][`date +%s`]--------";
	FILEFULLPATH=`readlink -f "${i}"`;
	FULLDIR=`dirname "${FILEFULLPATH}"`;
	## ORIGINAL DST DIR:
	DSTDIR="${FULLDIR}/_extracted"
	## DSTDIR  is where we are extracting, it has the suffix. Orignally it was just _extracted, but that was probablematic for files like part01.rar and part02.rar (in case there are many rars in the same folder)
	## DSTDIR="${FULLDIR}/_extracted-`date +%s`-`echo $$`"
	## another variation to DSTDIR that has filename - start ###
	### FNAMEPART=`basename "${FILEFULLPATH}"`
	### FSUFFIX=`echo "${FNAMEPART%.*}" | sed -e 's/[^A-Za-z0-9_-]/_/g'`
	### DSTDIR="${FULLDIR}/_ex-`date +%s`-${FSUFFIX}"
	#### DSTDIRFAIL="${DSTDIR}-FAIL-DELETE"
	## another variation to DSTDIR that has filename - end ###
	mkdir -p "${DSTDIR}" 2> /dev/null
	echo "### ${COUNT0}. EXTRACTING ${i} TO ${DSTDIR}:"
	echo "### unrar x $OVERWRITE ${i} ${DSTDIR}"
	EXTRACTED1="${i}.extracted"
	if [ -f "${EXTRACTED1}" ]; then
	   TMPW="PREVIOUSLY EXTRACTED"
	   COUNT1=$((COUNT1+1));
	   echo "[`date`] [`date +%s`] Attempted $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   echo "    File has already been extracted, to try again: 'rm $EXTRACTED1'"
	   cat "${EXTRACTED1}" | grep . | awk '{print "*       " $0;}'
	   echo "    *** $COUNT1 non-extractable rar files ($COUNT0 total rars scanned)"
	else
	   COUNT2=$((COUNT2+1));
	   echo "    *** $COUNT2 extractable rar files ($COUNT0 total rars scanned)"
	   ###unrar x $OVERWRITE "${i}" "${FULLDIR}/_extracted" |& grep . |& awk '{print "*    " $0;}' && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   STATUSFILE=/tmp/unrar2status-`date +%s`-`echo $$`
	   echo "FAIL" > $STATUSFILE
	   (unrar x $OVERWRITE "${i}" "${DSTDIR}" && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}" && echo "SUCCESS" > $STATUSFILE)  |& grep . |& awk '{print "*    " $0;}'
	   echo "$0|`date`/`date +%s`|`cat $STATUSFILE`|$SOURCE|$i" >> /var/log/unrar123.log
	   ### added this to delete rars - start ###
	   if grep -q "^SUCCESS$" "$STATUSFILE"; then
	   	   TMPW="EXTRACTION SUCCESSFUL"
	       COUNT3=$((COUNT3+1));
		   echo "   *** Extracted Succesfully - along with $COUNT3 out of $COUNT2 extractable rars"
	   else
	       TMPW="EXTRACTION FAILED"
	       COUNT4=$((COUNT4+1));
		   echo "   *** Failed to Extract - along with $COUNT4 out of $COUNT2 extractable rars"
		   #### echo "+ NOT SUCCESSFUL UNRAR -> Renaming Failed Destination"
		   #### echo "+ Renaming Failed Destination to: ${DSTDIRFAIL}"
		   #### mv -f "${DSTDIR}" "${DSTDIRFAIL}"
		   echo "+ NOT SUCCESSFUL UNRAR -> Removing Failed Destination"
		   echo "+ Deleting Failed Destination: ${DSTDIR}"
		   rm -rf "${DSTDIR}"
	   fi
	   ### added this to delete rars - end ###
	   # delete the status file, so as to not fill up the /tmp folder
	   rm $STATUSFILE
	fi
	echo "   *** TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" | tee -a /var/log/unrar123.log
	echo "* ${FILEFULLPATH} : ${TMPW}" >> /var/log/unrar123.brief
done;
echo "* TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" >> /var/log/unrar123.brief
cat /var/log/unrar123.brief >> /var/log/unrar123.allbrief
IFS=$OLDIFS)

=========================
unrar2extracted-delete-rars.sh
=========================
#!/bin/bash
# WHAT THIS DOES:
# The below script will extract each rar file into its current directory within a special _extracted folder in each directory for extra organization (the rars will make whatever subdirectories they need to make - which ever ones they contain of course).
# this will also delete the rar files after successful extraction (including the split/volume files)
# the extracted path is actually not _extracted but its "_ex-datetime-filename"
# WHAT TO DO:
# 1. fill out SOURCE variable (thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation). Or run it as script.
# - if run as script, it will look for files in current shell folder, not where the script resides (unless thats where your current folder is)
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE="`pwd`"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
echo "$0 STARTING RECURSIVE UNRAR & CREATING _extracted FOLDERS IN SAME FOLDER AS RAR FILES, STARTING HERE: $SOURCE"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
cd "${SOURCE}"
OLDIFS=$IFS
IFS=$'\n'
COUNT=0; COUNT1=0; COUNT2=0; COUNT3=0; COUNT4=0;
echo "#### --[$0][$$][`date +%D-%T`/`date +%s`]-- ####" > /var/log/unrar123.brief
for i in `find -type f | grep \.rar$`; do
	COUNT0=$((COUNT0+1));
	echo "### --------[`date +%D-%T`][`date +%s`]--------";
	FILEFULLPATH=`readlink -f "${i}"`;
	FULLDIR=`dirname "${FILEFULLPATH}"`;
	## ORIGINAL DST DIR:
	## DSTDIR="${FULLDIR}/_extracted"
	## DSTDIR  is where we are extracting, it has the suffix. Orignally it was just _extracted, but that was probablematic for files like part01.rar and part02.rar (in case there are many rars in the same folder)
	## DSTDIR="${FULLDIR}/_extracted-`date +%s`-`echo $$`"
	## another variation to DSTDIR that has filename - start ###
	FNAMEPART=`basename "${FILEFULLPATH}"`
	FSUFFIX=`echo "${FNAMEPART%.*}" | sed -e 's/[^A-Za-z0-9_-]/_/g'`
	DSTDIR="${FULLDIR}/_ex-`date +%s`-${FSUFFIX}"
	#### DSTDIRFAIL="${DSTDIR}-FAIL-DELETE"
	## another variation to DSTDIR that has filename - end ###
	mkdir -p "${DSTDIR}" 2> /dev/null
	echo "### ${COUNT0}. EXTRACTING ${i} TO ${DSTDIR}:"
	echo "### unrar x $OVERWRITE ${i} ${DSTDIR}"
	EXTRACTED1="${i}.extracted"
	if [ -f "${EXTRACTED1}" ]; then
	TMPW="PREVIOUSLY EXTRACTED"
	   COUNT1=$((COUNT1+1));
	   echo "[`date`] [`date +%s`] Attempted $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   echo "    File has already been extracted, to try again: 'rm $EXTRACTED1'"
	   cat "${EXTRACTED1}" | grep . | awk '{print "*       " $0;}'
	   echo "    *** $COUNT1 non-extractable rar files ($COUNT0 total rars scanned)"
	else
	   COUNT2=$((COUNT2+1));
	   echo "    *** $COUNT2 extractable rar files ($COUNT0 total rars scanned)"
	   ###unrar x $OVERWRITE "${i}" "${FULLDIR}/_extracted" |& grep . |& awk '{print "*    " $0;}' && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}"
	   STATUSFILE=/tmp/unrar2status-`date +%s`-`echo $$`
	   echo "FAIL" > $STATUSFILE
	   (unrar x $OVERWRITE "${i}" "${DSTDIR}" && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE" >> "${EXTRACTED1}" && echo "SUCCESS" > $STATUSFILE)  |& grep . |& awk '{print "*    " $0;}'
	   echo "$0|`date`/`date +%s`|`cat $STATUSFILE`|$SOURCE|$i" >> /var/log/unrar123.log
	   ### added this to delete rars - start ###
	   if grep -q "^SUCCESS$" "$STATUSFILE"; then
	   	   TMPW="EXTRACTION SUCCESSFUL"
	       COUNT3=$((COUNT3+1));
		   echo "   *** Extracted Succesfully - along with $COUNT3 out of $COUNT2 extractable rars"
		   VV=0
		   for j in `unrar la -v "${FILEFULLPATH}"  | awk '/^Archive:/{$1="";print $0}' | sed 's/^[ \t]*//;s/[ \t]*$//'`; do
			   VV=$((VV+1))
			   DELETEVOL="$j"
			   (echo -n "+ ${VV} SUCCESSFUL UNRAR -> Deleting rar volume: ${DELETEVOL}: "
			   rm -f "${DELETEVOL}" && echo "deleted!" || echo "delete failed!") |  tee -a "${EXTRACTED1}"
		   done
	   else
	       TMPW="EXTRACTION FAILED"
	       COUNT4=$((COUNT4+1));
		   echo "   *** Failed to Extract - along with $COUNT4 out of $COUNT2 extractable rars"
		   #### echo "+ NOT SUCCESSFUL UNRAR -> Renaming output folder & Not deleting rar volume[s]"
		   #### echo "+ Renaming Failed Destination to: ${DSTDIRFAIL}"
		   #### mv -f "${DSTDIR}" "${DSTDIRFAIL}"
		   echo "+ NOT SUCCESSFUL UNRAR -> Deleting output folder & Not deleting rar volume[s]"
		   echo "+ Removing Failed Destination: ${DSTDIR}"
		   rm -rf "${DSTDIR}"
	   fi
	   ### added this to delete rars - end ###
	   # delete the status file, so as to not fill up the /tmp folder
	   rm $STATUSFILE
	fi
	echo "   *** TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" | tee -a /var/log/unrar123.log
	echo "* ${FILEFULLPATH} : ${TMPW}" >> /var/log/unrar123.brief
done;
echo "* TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" >> /var/log/unrar123.brief
cat /var/log/unrar123.brief >> /var/log/unrar123.allbrief
IFS=$OLDIFS)

=========================
unrar3todir.sh
=========================
#!/bin/bash
# usage: $0 <diff directory to extract to>
# WHAT THIS DOES:
# this will take a folder structure with lots of rars, and copy it to another folder set, but extract all the rars nicely
# WHAT TO DO:
# 1. fill out SOURCE & DESTINATION variable
# or 1. Run as script "usage: unrar3todir.sh <directory>" - not it will extract every rar file recursively from current folder (not where script is, but where you are in the shell) to the dest folder specified
# note about the source: thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation
# note about the destination: this will only copy out the folder structure as is for rar files, then it will also make the correct folder structure that the rar files contained within them. When typing the destination folder, it doesnt matter if it ends in a / or doesnt (same goes for source)
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# make sure that the destination folder is not in the source folder
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=`pwd`
DESTINATION="$1"
if [ -z $DESTINATION ]; then echo -e "UNRAR RECURSIVELY TO DIFFERENT DIRS\nusage: $0 <directory to extract to>"; exit 1; fi
echo "$0 IS STARTING RECURSIVE UNRAR OF $SOURCE TO $DESTINATION"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
OLDIFS=$IFS
IFS=$'\n'
cd "${SOURCE}"
mkdir -p "${DESTINATION}" 2> /dev/null
DESTINATION=`readlink -f "${DESTINATION}"`
COUNT=0; COUNT1=0; COUNT2=0; COUNT3=0; COUNT4=0;
echo "#### --[$0][$$][`date +%D-%T`/`date +%s`]-- ####" > /var/log/unrar123.brief
for i in `find -type f | grep \.rar$`; do
	COUNT0=$((COUNT0+1));
	echo "### --------[`date +%D-%T`][`date +%s`]--------";
	FILEFULLPATH=`readlink -f "${i}"`;
	RELATIVEDIR=`dirname "${i}"`;
	NEWRDIR="${RELATIVEDIR#.}"
	DSTDIR="${DESTINATION}${NEWRDIR}"
	echo "### ${COUNT0}. EXTRACTING ${i} TO ${NEWRDIR}:"
	#mkdir -p "${DESTINATION}${NEWRDIR}" 2> /dev/null
	echo "### unrar x ${FILEFULLPATH} ${DSTDIR}";
	EXTRACTED1="${i}.extracted"
	if [ -f "${EXTRACTED1}" ]; then
	   TMPW="PREVIOUSLY EXTRACTED"
	   COUNT1=$((COUNT1+1));
	   echo "[`date`] [`date +%s`] Attempted $0 on SRC: $SOURCE, DST: $DESTINATION" >> "${EXTRACTED1}"
	   echo "    File has already been extracted, to try again: 'rm $EXTRACTED1'"
	   cat "${EXTRACTED1}" | grep . | awk '{print "*       " $0;}'
	   echo "    *** $COUNT1 non-extractable rar files ($COUNT0 total rars scanned)"
	else
	   COUNT2=$((COUNT2+1));
	   echo "    *** $COUNT2 extractable rar files ($COUNT0 total rars scanned)"
	   mkdir -p "${DSTDIR}" 2> /dev/null
	   ### unrar x $OVERWRITE "${FILEFULLPATH}" "${DESTINATION}${NEWRDIR}" |& grep . |& awk '{print "*    " $0;}' && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE, DST: $DESTINATION" >> "${EXTRACTED1}"
	   ### STATUS="FAIL"
	   STATUSFILE=/tmp/unrar3status-`date +%s`-`echo $$`
	   echo "FAIL" > $STATUSFILE
	   (unrar x $OVERWRITE "${FILEFULLPATH}" "${DSTDIR}" && (echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE, DST: $DESTINATION"; echo "SUCCESS" > $STATUSFILE;) >> "${EXTRACTED1}" || echo "[`date`][`date +%s`] Failed $0 on SRC: $SOURCE, DST: $DESTINATION - $FILEFULLPATH" >> ${DSTDIR}/failed-unrar3.txt) |& grep . |& awk '{print "*    " $0;}'
	   echo "$0|`date`/`date +%s`|`cat $STATUSFILE`|$SOURCE|$i --> $DESTINATION" >> /var/log/unrar123.log
	   if grep -q "^SUCCESS$" "$STATUSFILE"; then
	      TMPW="EXTRACTION SUCCESSFUL"
		  COUNT3=$((COUNT3+1));
		  echo "   *** Extracted Succesfully - along with $COUNT3 out of $COUNT2 extractable rars"
	   else
	      TMPW="EXTRACTION FAILED"
		  COUNT4=$((COUNT4+1));
		  echo "   *** Failed to Extract - along with $COUNT4 out of $COUNT2 extractable rars"
	   fi
	   rm $STATUSFILE
	fi
	echo "   *** TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" | tee -a /var/log/unrar123.log
	echo "* ${FILEFULLPATH} : ${TMPW}" >> /var/log/unrar123.brief
done;
echo "* TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" >> /var/log/unrar123.brief
cat /var/log/unrar123.brief >> /var/log/unrar123.allbrief
IFS=$OLDIFS)

=========================
unrar3todir-delete-rars.sh
=========================
#!/bin/bash
# usage: $0 <diff directory to extract to>
# WHAT THIS DOES:
# this will take a folder structure with lots of rars, and copy it to another folder set, but extract all the rars nicely
# this will also delete the rar files after successful extraction (including the split/volume files)
# WHAT TO DO:
# 1. fill out SOURCE & DESTINATION variable
# or 1. Run as script "usage: unrar3todir.sh <directory>" - not it will extract every rar file recursively from current folder (not where script is, but where you are in the shell) to the dest folder specified
# note about the source: thats where all of the rars are, well they dont necesarry have to be on the same folder level, they could be a few folders deep, but this will be the root of the operation
# note about the destination: this will only copy out the folder structure as is for rar files, then it will also make the correct folder structure that the rar files contained within them. When typing the destination folder, it doesnt matter if it ends in a / or doesnt (same goes for source)
# 2. pick whichever OVERWRITE option you want
# 3. copy paste the script into the shell (the parenthesis on the outsides of the script make sure it all runs nicely together)
# MORE INFO ON OVERWRITE VARIABLE:
# make sure that the destination folder is not in the source folder
# the overwrite variable, pick either -o+ for overwrite, -o- for not overwrite, or empty " " for prompts on overwrite. Make sure to hash out the ones you dont want. I like overwrite because then I ensure a good clean copy.
(SOURCE=`pwd`
DESTINATION="$1"
if [ -z $DESTINATION ]; then echo -e "UNRAR RECURSIVELY TO DIFFERENT DIRS\nusage: $0 <directory to extract to>"; exit 1; fi
echo "$0 IS STARTING RECURSIVE UNRAR OF $SOURCE TO $DESTINATION"
echo "OVERWRITE BIT IS (if nothing its unset, -o+ overwrite, -o- for not overwrite): $OVERWRITE"
OVERWRITE="-o+"
# OVERWRITE="-o-"
# OVERWRITE=" "
OLDIFS=$IFS
IFS=$'\n'
cd "${SOURCE}"
mkdir -p "${DESTINATION}" 2> /dev/null
DESTINATION=`readlink -f "${DESTINATION}"`
COUNT=0; COUNT1=0; COUNT2=0; COUNT3=0; COUNT4=0;
echo "#### --[$0][$$][`date +%D-%T`/`date +%s`]-- ####" > /var/log/unrar123.brief
for i in `find -type f | grep \.rar$`; do
	COUNT0=$((COUNT0+1));
	echo "### --------[`date +%D-%T`][`date +%s`]--------";
	FILEFULLPATH=`readlink -f "${i}"`;
	RELATIVEDIR=`dirname "${i}"`;
	NEWRDIR="${RELATIVEDIR#.}"
	DSTDIR="${DESTINATION}${NEWRDIR}"
	echo "### ${COUNT0}. EXTRACTING ${i} TO ${NEWRDIR}:"
	#mkdir -p "${DESTINATION}${NEWRDIR}" 2> /dev/null
	echo "### unrar x ${FILEFULLPATH} ${DSTDIR}";
	EXTRACTED1="${i}.extracted"
	if [ -f "${EXTRACTED1}" ]; then
	   TMPW="PREVIOUSLY EXTRACTED"
	   COUNT1=$((COUNT1+1));
	   echo "[`date`] [`date +%s`] Attempted $0 on SRC: $SOURCE, DST: $DESTINATION" >> "${EXTRACTED1}"
	   echo "    File has already been extracted, to try again: 'rm $EXTRACTED1'"
	   cat "${EXTRACTED1}" | grep . | awk '{print "*       " $0;}'
	   echo "    *** $COUNT1 non-extractable rar files ($COUNT0 total rars scanned)"
	else
	   COUNT2=$((COUNT2+1));
	   echo "    *** $COUNT2 extractable rar files ($COUNT0 total rars scanned)"
	   mkdir -p "${DSTDIR}" 2> /dev/null
	   ### unrar x $OVERWRITE "${FILEFULLPATH}" "${DESTINATION}${NEWRDIR}" |& grep . |& awk '{print "*    " $0;}' && echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE, DST: $DESTINATION" >> "${EXTRACTED1}"
	   ### STATUS="FAIL"
	   STATUSFILE=/tmp/unrar3status-`date +%s`-`echo $$`
	   echo "FAIL" > $STATUSFILE
	   (unrar x $OVERWRITE "${FILEFULLPATH}" "${DSTDIR}" && (echo "[`date`] [`date +%s`] Success $0 on SRC: $SOURCE, DST: $DESTINATION"; echo "SUCCESS" > $STATUSFILE;) >> "${EXTRACTED1}" || echo "[`date`][`date +%s`] Failed $0 on SRC: $SOURCE, DST: $DESTINATION - $FILEFULLPATH" >> ${DSTDIR}/failed-unrar3.txt) |& grep . |& awk '{print "*    " $0;}'
	   echo "$0|`date`/`date +%s`|`cat $STATUSFILE`|$SOURCE|$i --> $DESTINATION" >> /var/log/unrar123.log
	   ### added this to delete rars - start ###
	   if grep -q "^SUCCESS$" "$STATUSFILE"; then
	       TMPW="EXTRACTION SUCCESSFUL"
	       COUNT3=$((COUNT3+1));
		   echo "   *** Extracted Succesfully - along with $COUNT3 out of $COUNT2 extractable rars"
		   VV=0
		   for j in `unrar la -v "${FILEFULLPATH}"  | awk '/^Archive:/{$1="";print $0}' | sed 's/^[ \t]*//;s/[ \t]*$//'`; do
			   VV=$((VV+1))
			   DELETEVOL="$j"
			   ## DELETEVOLFULLPATH="$FULLDIR/$j"
			   (echo -n "+ ${VV} SUCCESSFUL UNRAR -> Deleting rar volume: ${DELETEVOL}: "
			   rm -f "${DELETEVOL}" && echo "deleted!" || echo "delete failed!") |  tee -a "${EXTRACTED1}"
		   done
	   else
	       TMPW="EXTRACTION FAILED"
	       COUNT4=$((COUNT4+1));
		   echo "   *** Failed to Extract - along with $COUNT4 out of $COUNT2 extractable rars"
		   echo "+ NOT SUCCESSFUL UNRAR -> Not deleting rar volume[s]"
	   fi
	   ### added this to delete rars - end ###
	   # delete the status file, so as to not fill up the /tmp folder
	   rm $STATUSFILE
	fi
	echo "   *** TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" | tee -a /var/log/unrar123.log
	echo "* ${FILEFULLPATH} : ${TMPW}" >> /var/log/unrar123.brief
done;
echo "* TOTALS: $COUNT0 scanned, $COUNT1 non-extractable(previously extracted), $COUNT2 extractable rars ($COUNT3 successful + $COUNT4 failed)" >> /var/log/unrar123.brief
cat /var/log/unrar123.brief >> /var/log/unrar123.allbrief
IFS=$OLDIFS)

 

4 thoughts on “UNRAR123 – UNRAR Recursively – my unrar tools – good for downloads of rars (works with split volumes)

Leave a Reply

Your email address will not be published. Required fields are marked *