Recursively change file extensions in Bash Recursively change file extensions in Bash bash bash

Recursively change file extensions in Bash


Use:

find . -name "*.t1" -exec bash -c 'mv "$1" "${1%.t1}".t2' - '{}' +

If you have rename available then use one of these:

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


If your version of bash supports the globstar option (version 4 or later):

shopt -s globstarfor f in **/*.t1; do    mv "$f" "${f%.t1}.t2"done 


I would do this way in bash :

for i in $(ls *.t1); do    mv "$i" "${i%.t1}.t2" done

EDIT : my mistake : it's not recursive, here is my way for recursive changing filename :

for i in $(find `pwd` -name "*.t1"); do     mv "$i" "${i%.t1}.t2"done