May 20 2009

unzip and unrar bash script

Do you ever download those files that are comprised of multiple zip files that always seem to extract individual rar files to their own folders. This would normally require the user to cut and paste all these rar files back into the original folder and then unrar them. This is very tedious, especially when there is lots of these files and folders. I’ve written this little shell script to automate this task for myself and figured that I would share. This script is extremely simple but it has worked great for every double archive that I have tried it on. As always any improvements and comments are welcome.

Call this script from the command line when your current working directory is the folder with all the zip files in it. To get your current working directory use the command ‘pwd’.

unzip -o \*.zip
for f in *.rar;do unrar -o- e “$f”;done
rm *.rar
rm *.zip

You may be asking why I was forced to escape the ‘*’ in the first line. If I didn’t do this then I got a lot of “caution: filename not matched:” errors on the unzip line. Not sure why and if anyone can shed some light on that it would be great. As for the option to the commands, read the man pages. And the for loop is pretty self explanatory.

Enjoy those giant image sets.

Share