Change Multiple File Extensions In Unix/Linux/Mac With “mv”

I recently experienced an issue where I wanted to change the extension on multiple jpeg files in a directory to have uniform case. This particular gallery directory had several hundred files and some were .JPG while others were .jpg.

A simple shell command can be used to perform renaming of all files to the extension of your choice:

# for file in *.JPG ; do mv $file `echo $file | sed ‘s/\(.*\.\)JPG/\1jpg/’` ; done

This renamed all files with upper-case extension, (.JPG), to lower-case extension, (.jpg).

Another common usage in my environment is to rename multiple HTML files:

# for file in *.html ; do mv $file `echo $file | sed ‘s/\(.*\.\)html/\htm/’` ; done

This will change all *.html files to *.htm.

…providing my ADHD with the obsessive-compulsive uniformity it needs for everything to be right in the world.

Sorry, comments are closed for this post.



© Copyright Nathan Mino 2021. All rights reserved.
Use of this web site constitutes acceptance of the nathanmino.com Terms Of Use and Privacy Policy
Remote Support