LinuxQuestions.org
Review your favorite Linux distribution.
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, 11:30 AM   #1
jim.thornton
Member
 
Registered: May 2007
Posts: 404

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, 12:05 PM   #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, 04:25 PM   #3
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,818

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
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, 04:41 PM   #4
jim.thornton
Member
 
Registered: May 2007
Posts: 404

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


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


All times are GMT -5. The time now is 09:11 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration