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
Written by Miguel
Related protips
2 Responses
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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#