Batch File Renaming

How many times have you had a bunch of files that you wanted to change the extension on? And all you really want to do is make mv work differently:

mv *.jpeg *.jpg

Well, if you’re on a Linux, Unix, or Mac box, you’re in luck – this is easy to achieve. All you need to do is list all of the files you’re looking for:

ls ./*.jpeg

…pipe that through sed, and apply a regular expression replacement (remove the jpeg):

ls ./*.jpeg | sed -e 's/\.jpeg//'

…and then use xargs to get the output of sed, store it in an expression, {}, and pass it to mv:

ls ./*.jpeg | sed -e 's/\.jpeg//' | xargs -t -i {} mv {}.jpeg {}.jpg

That should work on most boxes. Macs might freak and think that xargs -t -i {} should be xargs -t -I {}.