That approach comes with hefty filename limitations (which may or may not be of importance to the original poster, but I'll mention them for completeness):
Filenames cannot contain newlines (when reading find's output, it's impossible to distinguish between two filenames and one with an embedded newline. Unfixable.
Filenames cannot contain any of the other shell-special characters (space, tab, backslash, single-quote, double-quote, semicolon, ampersand, pipe, >, <, etc). Possibly fixable, by backslash escaping every such character, but it would be a brittle solution.
Unrelatedly, either find should be constrained to match only files ending in ".JPG" or the matching regular expression in sed should be anchored to the end of the line, with "JPG$". Otherwise, mid-filename ".JPG" sequences will match filenames not ending in ".JPG".
Regards,
Alister
---------- Post updated at 02:26 PM ---------- Previous update was at 01:52 PM ----------
If the solution must handle every allowable filename, I would suggest:
find . -type f -name \*.JPG -exec ./mvjpg.sh {} +
Where mvjpg.sh is:
#!/bin/sh
for f; do
mv "$f" "${f%.JPG}.jpg"
done
Obviously, you'll need to adjust the path to the shell script in the -exec primary to match its actual location on your system, if it's not on your $PATH.
There is if you care about handling filenames that have any IFS characters. Assuming that IFS has its default value, your code will choke on any filename that contains a space, tab, or newline.
Also, there is no way to fix that shortcoming. If you double-quote the command substitution in the for loop's list, it will always result in a list with a single item.
The shell substitution that the original poster's code uses works correctly and is part of the posix standard. Your subsitution is an extension and will mishandle filenames with an embedded ".JPG" sequence (though such a filename may be unlikely, the limitation should be mentioned).
---------- Post updated at 02:38 AM ---------- Previous update was at 02:34 AM ----------
That's a very nice approach, but alas rename is not a standardized utility and may not be present. If it is, your approach is most convenient.
By the way, you could speed it up by not having to invoke rename once per filename, using:
find -name '*.JPG' -exec rename .JPG .jpg {} +
Also, I get the impression, from reading the man page, that your solution may incorrectly rename files that contain an embedded .JPG before the end of the filename. It may be an uncommon scenario, but still, for completeness' sake, I mention it.