After searching and getting a lot of different answers on how to move all files in a project from one file pattern to another, I found this article had the simplest solution.

I was trying to move all files in a Jest project from having the suffix _spec.js to have .spec.js. The following line of bash got the job done:

for f in *_spec.js; do mv "$f" "${f/_spec/.spec}"; done

If you want to test this before actually moving the files and see what action will be done, add an echo before the mv call in the loop, which will print the mv calls that would be made:

for f in *_spec.js; do echo mv "$f" "${f/_spec/.spec}"; done

I also like the idea of using rename but this is not available by default on OS X and I do not want to install it since this is not a program I will be using often. It does have a much simpler syntax though and can be piped to find, which would look like:

find -name "*_spec.js" -type d | rename 's/_spec/\.spec/g'