This one’s really basic, but just because you’re an ace php developer doesn’t necessarily mean you’ve had a chance to discover all the ins and outs of bash and the linux command line. One of the guys in the office recently asked me how to make a change to multiple files in his code base with a single line command. Find and sed are your friends here. Since I’m a huge fun of doing as many things as possible with one liners, here’s the gist of what we did.
find . -name '*.php' -exec sed -i -e"s#search#replace#g" {} \;
Find the files you want, run sed on each one of them, edit inline with the included expression, done.
Big thing to note is sed using ‘#’ for a seperator and not ‘/’ . I believe the man page still talks about using a forward slash, but ‘#’ works.
The results from your find command are run through the {} so don’t forget that, and a find -exec must be terminated with a \;
Enjoy.