LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-06-2015, 10:30 AM   #1
jim.thornton
Member
 
Registered: May 2007
Posts: 430

Rep: Reputation: 19
Can someone please help me build a script?


I'm in the need of building a script to clean up my media library. I've been PVR'ing for years now and it's time to clean things up. For example, my TV Shows are saved as such:

/media/storage/Show Name/Season 1/Show Name - S01E01 - Episode Name.mp4

Over the years I've created a bunch of subdirectories further than that and I want to go through and clean those out. For example, the following directory might exist:

/media/storage/Show Name/Season 1/subtitles

If I use the find command, with -type d and -maxdepth 4, I have discovered that the subdirectory I want to delete is in the 4th level. There should be nothing valid in the 4th level and okay to delete.

I don't really know where to start. I tried using the find command with -mindepth 4 but that doesn't seem to work as I would expect. Basically, I want to scan through the library, then I want to test to make sure that the directory isn't "Season XX" and if it is a subdirectory within Season X then I would like to delete that subdirectory.

Any ideas how I can accomplish this?

FYI: I'm using Korrora 21 with BASH.
 
Old 05-06-2015, 11:05 AM   #2
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Try this:

Code:
find "/media/storage/Show Name" -mindepth 2 -type d
And if it finds correct sub-directory, then

Code:
find "/media/storage/Show Name" -mindepth 2 -type d -exec rm -fr "{}" \;
 
Old 05-06-2015, 03:25 PM   #3
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
Quote:
/media/storage/Show Name/Season 1/subtitles
as you are finding out
those "blank spaces" in the folder names are causing problems


as above use quotes " File Name " on the FULL path to the folders
 
Old 05-06-2015, 03:41 PM   #4
jim.thornton
Member
 
Registered: May 2007
Posts: 430

Original Poster
Rep: Reputation: 19
Quote:
Originally Posted by veerain View Post
Try this:

Code:
find "/media/storage/Show Name" -mindepth 2 -type d
And if it finds correct sub-directory, then

Code:
find "/media/storage/Show Name" -mindepth 2 -type d -exec rm -fr "{}" \;
Thank you! Worked perfectly.
 
  


Reply



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
How to build a Slackbuild script? Laodiceans Slackware 13 11-02-2010 04:23 AM
Kernel build script Kenny_Strawn Linux - Kernel 1 08-24-2010 07:30 PM
build a playlist with a script :) wademac Linux - Newbie 7 07-14-2009 01:48 PM
vsftpd build script 0.o Slackware 4 06-06-2005 11:58 AM
Script to build Virtualusers lapthorn Linux - Software 0 10-19-2004 05:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:25 AM.

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