Categories
Linux Ubuntu

Linux how to change the file extensions for multiple files in a directory

Where source is old extension and dest is new extension, in terminal type:

for x in *.source; do mv “$x” “${x%.source}.dest”; done

3 replies on “Linux how to change the file extensions for multiple files in a directory”

That works great if your file names don’t have any spaces in them. However if they do try this:

for f in *.OLD; do mv “$f” “`basename “$f” .OLD`.new”; done;

I most often use this for photos, a lot of cameras use an uppercase JPG as a file extension and some programs get confused (Thunderbird, I’m looking at you!) by uppercase file extensions.

I use it so often I even have an alias in my .bashrc.

alias JPG=’for f in *.JPG; do mv “$f” “`basename “$f” .JPG`.jpg”; done;’

Comments are closed.