I am completely new at Bash but I just can't seem to find a way to make it do what I want.
Imagine you have a tree directory with 2 files: /top.php and /test/bottom.php
How do I make my function look and replace say "hello" into "bonjour" in /top.php AND in /test/bottom.php?
So far the only way I have found to do this is by calling the same function twice with a different depth level:
find ./*.php -type f -exec sed -i 's/hello/bonjour/' {} \;
find ./*/*.php -type f -exec sed -i 's/hello/bonjour/' {} \;
Surely there's a recursive way to do this in one line?
Use an actual pattern for find instead of shell wildcard expansion:
find . -name '*.php' -type f -exec sed -i 's/hello/bonjour/' {} \;
Close:
find -iname '*.php' -type f -exec sed -i 's/hello/bonjour/' {} \;
Or
find -iname '*.php' -type f -print0 |
xargs -0 sed -i 's/hello/bonjour/'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With