replace a particular text in all the files using single line shell command

this one is very simple, without for or loop, and takes care of any number or nested directories

grep -rl 'oldText' [folderName-optional] | xargs sed -i 's/oldText/newText/g'


There are probably less verbose solutions, but here we go:

for i in *; do sed -i 's/old/new/g' "$i"; done

Mind you, it will only work on the current level of the file system, files in subdirectories will not be modified. Also, you might want to replace * with *.php, or make backups (pass an argument after -i, and it will make a backup with the given extension).


sed -i.bak 's/old/new/g' *.php

to do it recursively

find /path -type f -iname '*.php' -exec sed -i.bak 's/old/new/' "{}" +;