Amal Antony Amal Antony - 1 year ago 163
Linux Question

Recursively change file extensions in Bash

I want to recursively iterate through a directory and change the extension of all files of a certain extension, say

. What is the bash command for doing this?

Answer Source

If you have rename available then use:

find . -name "*.t1" -exec rename 's/\.t1$/.t2/' '{}' \;

If rename isn't available then use:

find . -name "*.t1" -exec bash -c 'mv "$1" "${1%.t1}".t2' - '{}' \;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download