Slackware This Forum is for the discussion of Slackware Linux.
|
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
01-17-2014, 09:52 AM
|
#1
|
Senior Member
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223
Rep:
|
How to extract all files on a directory and delete all files?
Hi, I download a lot of scene releases and they all come on rar files. Example: downloading an entire season of a tv show. The download is something like this:
Best.TV.Show.Ever.S01 (main directory)
->Best.TV.Show.Ever.S01E01 (sub-directory)
->Best.TV.Show.Ever.S01E02 (sub-directory)
->Best.TV.Show.Ever.S01E03 (sub-directory)
->Best.TV.Show.Ever.S01E04 (sub-directory)
->Best.TV.Show.Ever.S01E05 (sub-directory)
->Best.TV.Show.Ever.S01E06 (sub-directory)
Currently, I navigate through all directories and extract the episodes one by one. Then, I watch the episode and delete the files. Is there an easy way to extract all files and remove them automatically? Extracting one by one manually can be pretty boring and annoying. Thanks and sorry for my bad english.
Last edited by moisespedro; 01-19-2014 at 09:34 AM.
|
|
|
01-17-2014, 10:30 AM
|
#2
|
Member
Registered: May 2004
Distribution: Slackware
Posts: 215
Rep:
|
So there is one .rar file in each of those sub-directories and you want to extract each of them and then remove the .rar files and sub-directories?
If so, I think something like this should do it (I don't know the syntax for unrar, so I'm guessing on that.):
Code:
$ cd Best.TV.Show.Ever.S01
$ for DIR in `find . -type d`; do
> unrar $DIR/*.rar
> rm $DIR/*.rar
> rmdir $DIR
> done
Dave
|
|
|
01-17-2014, 01:01 PM
|
#3
|
Senior Member
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223
Original Poster
Rep:
|
Hmm, here is how they look like
http://i.imgur.com/kcKzT9v.jpg
EDIT: TO extract one has to use "unrar e" on the part 1 archive, then the others will be extracted too.
Last edited by moisespedro; 01-17-2014 at 01:04 PM.
|
|
|
01-17-2014, 02:18 PM
|
#4
|
Member
Registered: May 2004
Distribution: Slackware
Posts: 215
Rep:
|
OK. In that case, perhaps this:
Code:
$ cd Best.TV.Show.Ever.S01
$ for DIR in `find . -type d`; do
> unrar e $DIR/*01.rar
> rm $DIR/*
> rmdir $DIR
> done
|
|
|
01-17-2014, 04:19 PM
|
#5
|
Senior Member
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223
Original Poster
Rep:
|
Won't that exclude all files (including the extracted one?). Actually, won't it exclude the directory too?
|
|
|
01-18-2014, 10:55 AM
|
#6
|
Senior Member
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223
Original Poster
Rep:
|
It worked
Is there a way to do it but keep the directories?
|
|
|
01-19-2014, 07:42 AM
|
#7
|
Member
Registered: May 2004
Distribution: Slackware
Posts: 215
Rep:
|
Hi,
Sorry to not have replied earlier; been traveling.
Glad it worked. To keep the directories, just take out the line that reads
As for your worry that it would have excluded files, I'm assuming perhaps you were concerned by the "-type d". That option tells the find command to list directories (as opposed to all files). The lines output from the find command are then sequentially assigned to DIR for the execution of the for loop.
Dave
Last edited by xflow7; 01-19-2014 at 07:46 AM.
|
|
|
01-19-2014, 09:27 AM
|
#8
|
Senior Member
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223
Original Poster
Rep:
|
Thanks for the help What I was asking is that even if I don't remove the directories all the files are extracted to the main folder (instead of their respective folders). I used to use RARZombie for that (a java applet but, even know it is a java app, I can't get it working - it runs but it doesn't extract).
EDIT: nevermind, just had to replace "e" (to extract to the current folder) for "x" (to keep the full path). Thread is solved, many thanks
EDIT2: Actually it didn't work
Last edited by moisespedro; 01-19-2014 at 09:33 AM.
|
|
|
01-19-2014, 08:21 PM
|
#9
|
Member
Registered: May 2004
Distribution: Slackware
Posts: 215
Rep:
|
Oh, sorry. I thought you had wanted to delete the sub-folders initially, which is why I wrote it to extract to the main subdirectory.
If you want to end up with the extracted episodes in the sub-folders, then probably this:
Code:
$ cd Best.TV.Show.Ever.S01
$ for DIR in `find . -type d`; do
> cd $DIR
> unrar e *01.rar
> rm *.rar *.nfo *.sfv
> cd ..
> done
I think that should delete the .rar files as well as the .nfo and .sfv files, but leave the extracted files in their respective sub-dirs.
Happy to help.
Dave
Last edited by xflow7; 01-19-2014 at 08:24 PM.
|
|
|
01-21-2014, 12:55 PM
|
#10
|
Senior Member
Registered: Nov 2013
Location: Brazil
Distribution: Slackware
Posts: 1,223
Original Poster
Rep:
|
Thank you very much
|
|
|
All times are GMT -5. The time now is 12:03 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|