I have a directory and some of the files' extensions are in uppercase (.JPG) instead of lowercase.
I want to make sure every file has .jpg as its extension. How would I do this from a shell prompt?
I have a directory and some of the files' extensions are in uppercase (.JPG) instead of lowercase.
I want to make sure every file has .jpg as its extension. How would I do this from a shell prompt?
Using Shell Parameter Expansion:
for f in *.JPG; do
mv "${f}" "${f%%.JPG}.jpg"
done
The "
characters will take care of filenames containing spaces, as photographs often do.
/path/to/*.JPG
. You're welcome to submit your own answer, of course :)
Feb 14, 2012 at 21:17
If you can use external tools (not only bash), check rename
command!
rename .JPG .jpg *
The rename
is part of util-linux
.
perl
that accepts different arguments to do the same thing.
If you do have spaces in filenames:
for f in *.JPG; do [[ -f "${f}" ]] && mv "${f}" "${f/%JPG/jpg}"; done
if you don't have spaces in the filenames:
for f in *.JPG; do mv $f `echo $f | sed 's/JPG$/jpg/'`; done
mv
.
Feb 8, 2012 at 11:09