My iTunes library is on a NAS (WD MyCloud 4TB), and I have a number of TV series, organised by iTunes library in the usual:
'TV Shows' folder:
TV Show 1
|------------- Series 1
|-----------01 Episode Name.m4v
|-----------02 Episode Name.m4v
|...
|------------- Series 2
|-----------01 Episode Name.m4v
|...
|...
TV Show 2
|------------- Series 1
|-----------01 Episode Name.m4v
|-----------02 Episode Name.m4v
|...
|------------- Series 2
|-----------01 Episode Name.m4v
|...
|...
I have hard linked the whole TV folder to another folder, called Infuse. This folder will be read by the Infuse app on my Apple TV [this allows me to bypass having a computer with iTunes permanently switched on], so I need to rename all the hard-linked files as such:
TV Show 1
|------------- Series 1
|-----------TV Show 1 - S0101 Episode Name.m4v
|-----------TV Show 1 - S0102 Episode Name.m4v
|...
|------------- Series 2
|-----------TV Show 1 - S0201 Episode Name.m4v
|...
|...
TV Show 2
|------------- Series 1
|-----------TV Show 2 - S0101 Episode Name.m4v
|-----------TV Show 2 - S0102 Episode Name.m4v
|...
|------------- Series 2
|-----------TV Show 2 - S0201 Episode Name.m4v
|...
|...
I have so far found the solution (for example TV Show 1, Season 1 folder):
cd into each season folder for each show and run
for f in *; do mv $f "TV Show 1 E01S$f"; done
but this is really time consuming as I then need to
cd ../Season 2/
for f in *; do mv $f "TV Show 1 E02S$f"; done
cd ../Sesaon 3/
...
cd ../../TV Show 2/Season 1/
for f in *; do mv $f "TV Show 2 E01S$f"; done
...
and what I ideally want is to script pulling the name from the grandparent directory and the season number from the parent directory so I can write one short bash script and run it. Something like:
#!/bin/bash
a=[TV Show folder]
b=[Season folder]
c=[each episode]
for c in each a/b/
mv $c "$a - S0$bE$c" (or) rename $c "$a - S0$bE$c"
done
Can you help me implement it with a number of for loops or specific command?