First time poster so go easy on me haha.
Beginner linux user, starting out bash scripting and want to make a script to scan my TV Shows folder for fanart.jpg (every show has this file) create a duplicate, rename it (as I understand unix systmes do not auto rename files or allow files with same names in the one directory), and copy to a wallpaper folder.
I've read tons of articles and can not seem to find a relatively simple way of doing this.
So far all Ive got is:
cd /mnt/TV\ Shows/
find /mnt/TV\ Shows/ -name fanart.jpg
Which gives me a list of all my fanart.jpg files in their respective folders.
Ive tried a few different things after this like sed
mv
and cp
but just cant seem to get it working.
Target folder is /mnt/Wallpapers/Slideshow/
Any help would be gratefully appreciated.
Cheers!
Best Answer
Here is example script that users
find
, which output is piped to awhile
loop:Remove
echo
the do the action.The name of the destination file will consist of:
The numbering will start from
0
, because the variable$i
has not been pre-initialized. You can puti=1;
beforefind
to start numbering from1
.Here is more complicated bash script that uses the
globstart
option**
to make recursive search for a file within a folder. If there is a coincidence the file will be be copied to a destination folder. You can choice between different patterns of the destination file name by changing the inner (if-fi) part of the script.References:
While loop only processes the first entry of ssh command
Recursive bash script to collect information about each file in a directory structure