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

2 Comments

  1. 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. Thank you, I needed to do the same as you and found this info very useful.

Leave a Comment

Your email address will not be published. Required fields are marked *