Problem: A client sent me 164 images with incorrect extensions on them. I needed to change them all from .jpg to .png.
Fix: Open up terminal, navigate to the directory containing all the images and type:
ls *.jpg | awk '{print("mv "$1" "$1)}' | sed 's/jpg/png/2' | /bin/sh |
..that should do it! This one-liner makes use of sed and awk unix utilities.
Also.. append the string “gal” to all jpgs in the current dir:
for f in *.jpg; do mv $f gal-$f; done
And.. remove all spaces and replace with hyphens in all jpegs in a dir:
for f in * *.jpg; do mv “$f” “${f// /-}”; done