I’d like to recursively rename all directories containing the string foo by replacing that part of the string with Bar. I’ve got something like this so far, but it doesn’t quite work. I’d also like foo to be searched case-insensitive.
find . -type d -exec bash -c 'mv "$1" "${1//foo/Bar}"' -- {} \;
Are there any elegant one-liners that might be better than this attempt? I’ve actually tried a few but thought I’d defer to the experts. Note: i’m doing this on a Mac OS X system, and don’t have tools like rename installed.
Try the following code using parameter expansion
But your best bet will be using Perl’s
rename(usable in any OS):And if you are using
bash4orzsh(**mean recursive):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.