Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Rails sometimes I need to rename several directories and files, e.g.:

app/models/person.rb
app/views/persons/_person.haml
app/controllers/persons_controller.rb
----
app/models/user.rb
app/views/users/_user.haml
app/controllers/users_controller.rb

I've exhausted looking up solutions. Does anyone know of a simple command line tool that I can install? E.g. mvall . person user.

share|improve this question
3  
Look at the Related questions on the right column. There are lot of answers to this question. –  Antoine Lecaille Oct 24 '12 at 20:10

1 Answer 1

I'm sure there are better ways to do it, but here's my implementation.

$ old=person; new=user; for i in $(find ./ -name "*$old*"); do mv $i $(echo $i | sed 's/'$old'/'$new'/g'); done

All the tools are in bash, so nothing needs to be installed.

share|improve this answer
    
You could also use find to execute your changes (rather than just locate the targets), It probably depends on whether you're more comfortable with find or bash. –  Dominic Cronin Oct 24 '12 at 21:00
    
@Rusty: for i in $(find . …) will fail if there are filenames that contain spaces. And you don’t need to say “./”. –  Scott Oct 24 '12 at 22:33
    
@Dominic: Is find guaranteed to behave sanely if you rename directories while it is traversing the directory tree? –  Scott Oct 24 '12 at 22:33
    
@Scott - good question. Don't know the answer –  Dominic Cronin Oct 24 '12 at 22:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.