Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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. – alecail Oct 24 '12 at 20:10

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .