Find and replace string recursively in Linux

We can use the combination of 'find' command and 'sed' command for achieving the same.

#find . -type f -print0 | xargs -0 sed -i '' -e 's/string1/string2/g'

Note to replace 'string1' and 'string2' with old and new keywords appropriately.

This command will replace the keyword 'string1' with 'string2' for all files in current directory recursively.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *