Daily Archives: November 1, 2008

Edit a line in all php files in a directory with find and sed

Here is about the simplest example I could come up with, to change a reference to a new include directory location in a codebase.

You can of course do fancier things should you wish to dump your results to a directory before overwriting your files.

#!/bin/sh
for files in `find *.php`
do
sed ‘s/..\/..\/adminincl/includes/g’ $files > ‘temp’.$files && mv ‘temp’.$files $files
done