You could use find and xargs:
$ find some_folder -type f -name "*.bub" |
sed "s/\.bub$//" |
xargs -I% mv -iv %.bub %.aaa
`some_folder/a.bub' -> `some_folder/a.aaa'
`some_folder/v.bub' -> `some_folder/v.aaa'
`some_folder/dr.bub' -> `some_folder/dr.aaa'
`some_folder/catpictures/or.bub' -> `some_folder/catpictures/or.aaa'
`some_folder/catpictures/on.bub' -> `some_folder/catpictures/on.aaa'
... which you could generalise to a bash function:
$ extmv () {
find "${1}" -type f -name "*.${2}" |
sed "s/\.${2}$//" |
xargs -I% mv -iv "%.${2}" "%.${3}"
}
... which you'd use like this:
$ extmv some_folder/ bub aaa
**instead. In the second version the "" are missing. Andsedis not necessary. bash can do that itself:mv "$f" "${f%.bub}.bub"– Hauke Laging Jun 09 '13 at 23:36shopt -s globstarfollowed byfor f in **/*.bub; do mv -iv "$f" "${f/.bub/.aaa}"; done(which does work to arbitrary depths of recursion, and doesn't require the*.bubyou included). – Jun 09 '13 at 23:45globstaris set then ** goes arbitrarily deep. One could say thatshopt -s globstarshould be added to your**answer. – Hauke Laging Jun 09 '13 at 23:47globstaroption as mentioned by myself and @HaukeLaging in the comments above? If not,**is the same thing as*(which would explain your result). – Jun 09 '13 at 23:53**/*bubshould be**/*.bub), and as mentioned, the preceding*.bubis redundant. – Jun 09 '13 at 23:56findversion is a lot safer, since it won't fail on directories whose names end.bub. – rici Jun 10 '13 at 01:40