Batch rename file extensions from .jpg to .png in terminal

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.

2 thoughts on “Batch rename file extensions from .jpg to .png in terminal”

  1. And.. remove all spaces and replace with hyphens in all jpegs in a dir:
    for f in * *.jpg; do mv “$f” “${f// /-}”; done

Leave a Reply

Your email address will not be published. Required fields are marked *