I have a lot of files names “strings.js” I’d rather were named “messages.js.”

$ find test -type f -name strings.js
test/a/strings.js
test/a/b/strings.js
test/strings.js

How do you rename files across directories via the command line? Tricky shell expansion? find -exec? Some hidden mv option? rename (if it’s installed)?

I have been goofing with this all morning. Here’s the solution I finally found.

This will rename each of them.

find test -type f -name strings.js | xargs -I{} \
  sh -c 'mv -v "$1" "$(dirname $1)/messages.js"' -- {}

I’m eager to get back to what I was doing, so I’m not going to explain all this. It’s simple if you break it down. This was hard to find, so I’m throwing it on the interwebs for future me… and you!