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. Andsed
is not necessary. bash can do that itself:mv "$f" "${f%.bub}.bub"
– Hauke Laging Jun 09 '13 at 23:36shopt -s globstar
followed 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*.bub
you included). – Jun 09 '13 at 23:45globstar
is set then ** goes arbitrarily deep. One could say thatshopt -s globstar
should be added to your**
answer. – Hauke Laging Jun 09 '13 at 23:47globstar
option 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**/*bub
should be**/*.bub
), and as mentioned, the preceding*.bub
is redundant. – Jun 09 '13 at 23:56find
version is a lot safer, since it won't fail on directories whose names end.bub
. – rici Jun 10 '13 at 01:40