Searching a file hierarchy for strings

A colleague asked today how to search a set of directories for files containing a particular string and this is what I came up with:
find . | xargs grep gnu
where gnu was my search term. The find command with the dot alias as input recursively descends the file hierarchy from the present working directory. The output of find is piped into xargs which is a very useful little utility that takes the input from find as a long list and splits it into sub-lists, calling grep for each sublist in turn, where in this case each sublist is a filename that grep searches. Obviously he was looking for a different search term than gnu and he was only wanting to search particular file types but this was the basics of his solution.
Posted
Views
Filed under: