Register
It is currently Mon Jul 28, 2014 4:30 pm

Auto extract rar files from multiple directories


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Tue Nov 08, 2011 4:01 am   

Joined: Tue Nov 08, 2011 3:45 am
Posts: 2
Hi all, first post. I know this has been broached before and I nearly have it down myself but I just can't figure the last step.

Basically, this is what I have:
~/directory1/subdirectory1/*.rar
~/directory1/subdirectory2/*.rar
~/directory2/subdirectory1/*.rar
etc..

I want to be able to extract all the rar files while keeping the file structure but moving all of the contents into an "unrared" directory. EG:
~/unrared/directory1/subdirectory1/extracted.files
~/unrared/directory1/subdirectory2/extracted.files
~/unrared/directory2/subdirectory1/extracted.files

So far I have this:
Code:
for f in `find . | grep .rar`
do
unrar x -o- "$f" ./unrared/
done


This will move the extracted files into the new directory, but will not keep the file structure.

I was thinking that I could move the files to the new structure first and then delete the archives as I extract them, but I would prefer not to as I am working with large amounts of data.


EDIT: you may be able to tell that I'm pretty much a beginner, so please go easy :)


Top
 Profile  
 PostPosted: Tue Nov 08, 2011 4:42 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
Code:
for f in $(find . -name \*.jpg) ; do
    dir=./unrared/${f%/*}
    mkdir -p $dir
    unrar x -o- "$f" $dir
done


Top
 Profile  
 PostPosted: Tue Nov 08, 2011 5:03 am   

Joined: Tue Nov 08, 2011 3:45 am
Posts: 2
Yep, perfect (changing jpg to rar of course :D ). Thanks for your help.


Top
 Profile  
 PostPosted: Tue Nov 08, 2011 7:48 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
d31b0y wrote:
Yep, perfect (changing jpg to rar of course :D ). Thanks for your help.

Heh, sorry. I did not have any rar files handy, so tried on jpegs and forgot to switch back :)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP