Linux has a handy rename command which is great for easily renaming file extensions within a directory.
> rename .htm .html *.htm
MacOS however has no such command.
Fortunately, Ben Han documented a nice work around by creating a simple script.
(Click here for a reminder on how to create MacOS scripts)
#!/bin/sh for f in *.$1 do mv $f ${f%$1}$2 done
It uses the mv command and loops through your directory doing the move based on whatever parameters you pass in.
For example to change all my pngs to jpgs all I have to do now is navigate to the target directory and type:
> chgext.sh png jpg
And voila! All my pngs are now jpgs.
Thanks again Ben for this great tip.
May 26, 2012 @ 13:52:13
Changing mv $f ${f%$1}$2 to mv “$f” “${f%$1}$2” will support filenames with spaces
May 29, 2012 @ 15:19:11
That’s much better. Thank you for taking the time to share Lubomir.
Mar 11, 2013 @ 10:59:43
– And voila! All my pngs are now **renamed** to jpgs
FTFY, the contents (png or whatever data) hasn’t been altered.