linux replace string in files recursively 1

linux replace string in files recursively

find . -type f -name "*.txt" -exec sed -i'' -e 's/foo/bar/g' {} +

Here is what the above code is Doing:
1. find . -type f -name “*.txt”
– find all files in the current directory and subdirectories that end with .txt
2. -exec sed -i” -e ‘s/foo/bar/g’ {} +
– execute the sed command on each file found in step 1
– the {} is a placeholder for the file name
– the + at the end of the command tells find to execute the command on as many files as possible

Similar Posts