Quickly renaming multiple file extensions with bash

Posted by & filed under Uncategorized.

I needed to quickly rename a bunch of file extensions in a directory. This one liner made quick work of it:

for old in *.JPG; do cp $old `basename $old .JPG`.jpg; done

basename, when given a file name and a extension spits out something like this:

user@server$ basename derp.txt .txt
derp
user@server$

Which we then use to append the proper extension (.jpg) in the example and done.