Category: Bash

Recursive unrar into each folder…

I’m not sure why this was so hard to find, but now it’s working… I was initially working on having “find” -exec UnRAR but it didn’t seem to work too well (I couldn’t find a good one-liner to separate file directory and full-filename to put into the find -exec command, if you have one, let me know).

#!/bin/bash
find $PWD -type f -name '*.rar' -print0 | 
while IFS= read -r -d '' file; do
dir=$(dirname "$file")
	unrar e -o+ "$file" "$dir"/ 
done

(some parts of the script was inspired from other online sources)

Make a bash-script change directory to where it is located!

In case you have files that are located in the same directory as the script that are read by the script, and you are to lazy to make it a configuration variable 🙂

SCRIPT=$(readlink -f $0)
SCRIPTPATH=`dirname $SCRIPT`
cd $SCRIPTPATH