Is there a way to quickly change all the file extensions of all files in a folder?

I have a large folder of .m4b audio books which in their current format won't play on my Android phone. However they do work fine if they are renamed to .m4a

Is there a quick method or terminal command that can rename every .m4b file in a folder to .m4a? There is no need for any conversion of the files, simply renaming the file extension works perfectly fine.

1

2 Answers

This will do the job for you.

rename 's/.m4b$/.m4a/' *.m4b

For a test run you can use this command:

rename 's/.m4b$/.m4a/' *.m4b -vn

-v means "verbose" and it will output the names of the files when it renames them.

-n will do a test run where it won't rename any files, But will show you a list of files that would be renamed.

2

A very quick way to rename files, if that is all you need to do, and do not need to convert them to another format, is to use Bash's parameter expansions, which are detailed very nicely at the Bash wiki.

There are several different ways of changing the extension, but I use here the simple ${var/original/replacement} paradigm:

for file in *.m4b; do mv -- "${file}" "${file/%m4b/m4a}"; done

If you want to see what would be changed by the command, place echo before mv and the changes will be listed.

Needless to say this oneliner could be modified for other files too, and you can also use parameter expansions to remove file extensions too.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like