20070727 recursively grep files - plembo/onemoretech GitHub Wiki
title: recursively grep files link: https://onemoretech.wordpress.com/2007/07/27/recursively-grep-files/ author: lembobro description: post_id: 670 created: 2007/07/27 02:23:00 created_gmt: 2007/07/27 02:23:00 comment_status: open post_name: recursively-grep-files status: publish post_type: post
recursively grep files
From Gary Utz, just a one liner to recursively grep on any machine equipped with find, xargs and grep. I use it to search through Apache conf files. Here's the quintessential example:
find . -name "*.conf" | xargs grep 'string you're looking for'
Note that it's always best to narrow your search by specifying a file name, part file name or extension. In the example I've specified files with the ".conf" extension. I could just as easily used ".php" or ".*", the latter being the "greediest" and bound to take the longest depending upon how many files you have to go through. You can also bound the search in time by using the "-mtime" option (see this post for more on that).
Copyright 2004-2019 Phil Lembo