LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-18-2014, 06:30 PM   #1
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Rep: Reputation: 30
Need a little help in making a script to help automate unraring


this is what i have to far it works but for some unknown reason the files aren't extracted to the same folder as the rar files but the parent folder

Code:
#!/bin/sh

dir=$1

find "$dir" -name "*part1.rar" -exec unrar -y -o- x {} "$dir" \;
find "$dir" -name "*part01.rar" -exec unrar -y -o- x {} "$dir" \;
find "$dir" -name "*part001.rar" -exec unrar -y -o- x {} "$dir" \;
find "$dir" -name "*.r00" -exec unrar -y -o- x {} "$dir" \;
find "$dir" -name "*.rar" -exec unrar -y -o- x {} "$dir" \;

fi
also a way to have all 5 rar types together in one line would be really cool

(note $1 / $dir = /temp/some.random.folder.name and the extract folder is for some reason /temp)

Last edited by steve51184; 01-18-2014 at 06:35 PM.
 
Old 01-18-2014, 08:46 PM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
With the find command:

the option -exec causes the command to be executed in the starting directory, in this case the value in $dir.
the option -execdir causes the command to be executed in the subdirectory containing the file with the matching name. However, for security reasons, is you use -execdir find does not want . ( the current dir ) to be in your PATH.

AFAIK, unrar wants the directory into which you want it to extract the files, to already exist.
So if you just want the files extracted to the directory containing the rar file, you could pass . to unrar. You can "or" conditions together using the -o option. Also, AFAIK although it doesn't necessarily have to be, the "command" ( in this case x ) to unrar is supposed to be right after unrar itself. Examples:

unrar extracts files to the directory /home/me/wherever:
Code:
find /home/me/wherever \( -name '*part1.rar' -o -name  '*.rar' \) -exec unrar x -o- -y '{}' . \;
unrar extracts files to the directory containing the .rar file:
Code:
find /home/me/wherever \( -name '*part1.rar' -o -name  '*.rar' \) -execdir unrar x -o- -y '{}' . \;
unrar extracts files to the existing sub-directory named sub within the directory containing the .rar file:
Code:
find /home/me/wherever \( -name '*part1.rar' -o -name  '*.rar' \) -execdir unrar x -o- -y '{}' sub \;
unrar extracts files to the sub-directory named some_dir within the /tmp directory:
Code:
find /home/me/wherever \( -name '*part1.rar' -o -name  '*.rar' \) -execdir unrar x -o- -y '{}' /tmp/some_dir \;
HTH.

Last edited by rigor; 01-18-2014 at 08:49 PM.
 
Old 02-01-2014, 04:33 PM   #3
steve51184
Member
 
Registered: Dec 2006
Posts: 381

Original Poster
Rep: Reputation: 30
thank you for the reply it's working perfectly

would it be possible to also once the archive has been extracted (successfully?) to then delete the files?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a script to automate slackbuilds (perl) mkoco Slackware 5 01-13-2011 02:57 PM
quick way to automate making cron jobs to delete files after 12hrs? steve51184 Linux - Software 16 03-05-2010 12:30 AM
LXer: Speaking Unix, Part 6: Automate, automate, automate! LXer Syndicated Linux News 0 01-04-2007 09:54 AM
Script to automate tasks immortaltechnique Red Hat 2 10-08-2006 10:46 PM
Automate SSH Script Gentoo20 Linux - General 11 03-22-2006 06:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration