Thursday, January 17, 2013

Search a string in multiple files including the files in sub directories 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' {} \;

No comments:

Post a Comment