Last Updated: February 25, 2016
·
982
· miguelperez

rename multiple files given a pattern

This might come in handy when renaming a controller or model (in rails).

If you are doing things right (and you should) you should have lots of files for tests and views that follow the same name convention, then renaming all those files manually can be cumbersome.

find . -name 'REGEX-PATTERN' -exec bash -c 'mv $0 ${0/REGEX-PATTERN/NEW-STRING}' {} \;

for example:

find . -name '*user*.rb' -exec bash -c 'mv $0 ${0/user/admin}' {} \;

will change all the file names, changing user for admin. where the file ends in .rb

2 Responses
Add your response

uhhhh.i think use rename command will make this more easier.
for example:
rename 's/user/admin/' user.rb

over 1 year ago ·

You are right but I have seen that way it will not look recursively on the directory tree.

Is there a way to make that happen?

over 1 year ago ·