Hey everyone, just now joined because I didn't want to go onto Ubuntu forums and start asking about how to write shell scripts. Seems like this is a pretty active forum for exactly what I need.
I'm trying to modify a shell script I found online, the end goal is to have it find all files in the directory it's ran AND all subdirectories, named folder.jpg, Folder.jpg, maybe a couple more, and make thumbnails of them.
I found this script earlier, which initially was trying to resize ALL files.. mp3 and what not (because of the FILES=* I'm guessing):
#!/bin/bash
FILES=*
for f in $FILES
do
echo �Processing $f file...�
convert -thumbnail 235x $f sm_$f
done
So, I looked at this and figured I could probably replace the FILES=* with FILES=folder.jpg. Sure enough, it worked. But when I then assumed that FILES=folder.jpg Folder.jpg would work for both, I was sadly disappointed. No luck with a comma and space, comma no space, semicolon, etc. I believe with a semicolon after the first file, the script at least ran again.... lol
I've been trying to look it up but having no luck, there has to be some easy way to specify multiple file names in that situation.
As far as making it work on all subdirectories as well, I couldn't find much on that, but I did manage to read that I could do this....
find /your/dir/with/subdirs -type d -exec sh -c 'cd "{}" ; /path/to/your/script.sh ;' \;
Sure enough, it found the file I put in my test directory named folder.jpg, as well as the one in a nested directory! Would be nice to have it all packaged in a script just for the sake of not having to copy and paste that every time, but that works for now...
Also I just read about the option of making a "loop wrapper", like this...
#! /bin/bash
cd /path/to/top/level/directory
for d in */ ; do
pushd $d
# call your script here
popd
done
And plan on trying that here in a little. SO, it sounds like I'm good to go on the subdirectories part. But what about the multiple file names? Is there a way I can just put it in to the script easily, or I imagine somehow I could parse it into that find command I was using.
Also, with the original script it creates the thumbnails with the name "sm_*original-filename*.... If possible I'd like to change that to have them be named something like folder_small.jpg, or even something completely different like album_art_thumb.jpg.
When I tried changing "convert -thumbnail 235x $f sm_$f" to "convert -thumbnail 235x $f $f_small", it was a no-go. Didn't want to run at all. I imagine there's an easy way to fix that but this language is all new to me. I don't know anything besides some HTML, CSS, and how to get around on a Unix/Linux shell (been using nothing but Linux as my OS for about 8 years or so now... off and on before that since I was a little kid).
If you could please take the time and point me in the right direction, I'd really appreciate it! Again just trying to:
- Specify multiple filenames to target, in the FILES= or otherwise...
and 2. How to change the end filename from sm_* to something that isn't text followed by the old filename.
And if you've got the time, maybe even help with the part about making it work recursively on all sub-directories.
Thanks! Glad to have found this forum. I can see how learning to make these scripts could really make a lot of things easier in the future...
Zac