I currently run plex on a Beelink running ubuntu, and to date, all files associated with each movie (movie file, associated images, and subtitles) are all in the same parent directory. for the most part that's okay, but for movies with multiple subtitles, it can get messy. e.g.
/Movies
/Avatar (2009)
Avatar (2009).mkv
Avatar (2009).eng.srt
Avatar (2009).en.forced.ass
Avatar (2009).en.sdh.srt
Avatar (2009).de.srt
Avatar (2009).de.sdh.forced.srt
It seems that now plex will find subtitles places in a "subs" or "subtitles" folder. So in order to tidy things up, how can I recursively go through the parent movie directory, and for each individual movie folder, move any subtitles files into a "subtitles" folder like so?
/Movies
/Avatar (2009)
Avatar (2009).mkv
/Subtitles
Avatar (2009).eng.srt
Avatar (2009).en.sdh.srt
Avatar (2009).de.srt
Avatar (2009).de.sdh.forced.srt
For TV shows, there may be multiple levels under the parent folder, e.g.
**Old:**
/TV Shows
/Game Of Thrones
/Season 02
Game Of Thrones - s02e03.mp4
Game Of Thrones - s02e03.eng.srt
Game Of Thrones - s02e03.en.forced.srt
**New:**
TV Shows
/Game Of Thrones
/Season 01
Game Of Thrones - s01e03.mp4
Game Of Thrones - s01e04.mp4
/Subtitles
Game Of Thrones - s01e03.eng.srt
Game Of Thrones - s01e04.eng.srt
/Season 02
Game Of Thrones - s02e03.mp4
/Subs
Game Of Thrones - s02e03.eng.srt
Game Of Thrones - s02e03.en.forced.srt
Even better would be the option to only move if not already in a subtitles folder...
Will find the path of every
.srt
file in the current working directory, recursively, excluding those contained in a directory named "Subtitles", printing only their basename and filtering out duplicates, creating a "Subtitles" directory inside each resulting path (if not existing) and moving every.srt
file at its level inside it.It will deal with
.srt
files located at any depth of the current working directory, and so with the "TV Shows" directory as well.The command will perform a dry run; if the output looks good, run the actual command:
Here's another approach. Use bash's
globstar
option to allow for recursing into subdirectories. Fromman bash
:So
**/
will only match directories, but it will include sub-directories. With this in mind, you can do:I tested it using this set of files and directories:
After running the command above, I ended up with:
Note that it will throw out some warnings for cases where there are no srt files in a directory since it will then try to run
mv directory_name/*srt directory_name/Subtitles
but since the*.srt
glob matches nothing, it will return itself (unless you have thenullglob
option activated), and as there is no file whose name is literally*srt
, it will fail. This is also why I had to addrmdir **/Subtitles
to remove emptySubtitles
directories. You can safely add2> /dev/null
to the end of themv
command to hide these warnings.Alternatively, you can do something slightly more complex and only create the dir and try to copy when you know you have
*.srt
files:Which results in the desired output in a single pass. To avoid moving files if they are already in a
Subtitles
directory, use theextglob
bash option that lets you build more complex globs, and just look for any directory whose name is notSubtitles
: