Mass file extension renaming in Linux


Recently I had to change the file extensions on a lot of files in multiple directories for an asterisk install. Bascially I needed to change .g711a to .alaw in the current directory and all subdirectories.

I was easily able to accomplish this in once single line which hopefully somebody may find a use for:

find . -name '*.g711a' | sed -e "s/^\(.*\)\.g711a$/\1\.g711a \1\.alaw/g" | xargs -n 2 mv -f

  1. #1 by Buzz on September 3, 2009 - 8:49 am

    On Linux at least you can use

    rename -n ‘s/\.oldext/\.newext/’ ./*.oldext

    You can also use -v to get a verbose output as each file is renamed.

  2. #2 by Jon on August 18, 2014 - 10:13 am

    Thank you, I needed to do the same as you and found this info very useful.

(will not be published)