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.

Comments

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

  1. Ben avatar
    Ben

    Also.. append the string “gal” to all jpgs in the current dir:
    for f in *.jpg; do mv $f gal-$f; done

  2. Ben avatar
    Ben

    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 *