Search a string in multiple files recursively
Almost every unix programmer will need this at least once in a day.For searching a string abc in all the files in the current direcory we use:
grep 'abc' *
If you want to serach in files which are under any sub directories also including the files in the current directory then we have to combine both find and grep:
find . -type f|xargs grep 'abc'
Another possible way is using exec of find command:
find . -type f -exec grep 'abc' {} \;
And how would i do it ..if I want to delete all those files with matching strings?
ReplyDeletefind . -type f|xargs perl -i -lne 'print if(/abc/)'
ReplyDelete