Recursive Unrar Script

If you’re looking for a code to recursively unrar files in a sub-directory I made a quick script that can be used!

#!/bin/bash
#This ensures that 2 parameters are passed to the script
if [ $# -ne 2 ]
	then
		echo "Usage is ./script <source> <desination>"
		exit
fi
#Stores the passed parameters
SOURCE=$1
DESTINATION=$2

#For each file in the subdirectory of the source. If they're a directory enter
#them and unrar them. Then move them to the destination.
for x in $SOURCE/*
        do
                if [ -d $x ]
                        then
                                cd $x
                                unrar e *.rar
                                mv *.{avi,mp4,aac,wmv,ogg,mkv,mpg} "$DESTINATION"
                fi
        done
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s