Recursively search through all files under a directory and replace a specific word wherever it appears
grep -rl 'oldword' . | xargs sed -i 's/oldword/newword/g'
grep -rl ‘oldword’ . -r → recursive -l → only list filenames where the word exists . → start from the current directory xargs sed -i ‘s/oldword/newword/g’ sed -i → edit files in place s/oldword/newword/g → substitute all occurrences globally in each file
find . -type f -exec sed -i 's/oldword/newword/g' {} +
find . -type f → find all files -exec … {} + → execute sed on all files found This avoids problems with filenames containing spaces or special characters.
perl -pi -e 's/oldword/newword/g' $(find . -type f)
-p → loop through each line of each file -i → in-place edit -e → execute code