Modify all files in subdirectories


How to modify all files in some subdirectories, however deeply nested? As an example suppose we wish to change the text "Hello World" to "hello world" in all php files under the top directory /home/dir/. Here's a simple one line command which does this:


find /home/dir/ -name \*.php -exec perl -pi -e 's/Hello World/hello world/g' {} \;


This can also be re-written as:

perl -e 's/Hello World/hello world/g' -pi $(find /home/dir/ -name \*.php)


This will modify all php files in /home/dir/ and in all directories under this.