Try the following code using parameter expansion
find . -type d -iname '*foo*' -depth -exec bash -c '
echo mv "$1" "${1//[Ff][Oo][Oo]/BAr}"
' -- {} ;
But your best bet will be the prename
command (sometimes named rename
or file-rename
)
find . -type d -iname '*foo*' -depth -exec rename 's@Foo@Bar@gi' {} +
And if you are using bash4
or zsh
(**
mean recursive):
shopt -s globstar
rename -n 's@Foo@Bar@gi' **/*foo*/
If it fit your needs, remove the -n
(dry run) switch to rename for real.
SOME DOC
rename was originally written by Perl's dad, Larry Wall himself.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…