LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can someone please help me build a script? (https://www.linuxquestions.org/questions/linux-newbie-8/can-someone-please-help-me-build-a-script-4175541779/)

jim.thornton 05-06-2015 10:30 AM

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.

veerain 05-06-2015 11:05 AM

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 "{}" \;

John VV 05-06-2015 03:25 PM

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

jim.thornton 05-06-2015 03:41 PM

Quote:

Originally Posted by veerain (Post 5358750)
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.


All times are GMT -5. The time now is 12:18 PM.