Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site wgivax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!mcnc!unccvax!wgivax!mo From: mo@wgivax.UUCP Newsgroups: net.unix Subject: Re: Need unix command file HELP! Message-ID: <135@wgivax.UUCP> Date: Sun, 2-Feb-86 09:43:44 EST Article-I.D.: wgivax.135 Posted: Sun Feb 2 09:43:44 1986 Date-Received: Tue, 4-Feb-86 03:23:10 EST References: <245@aero.ARPA>, <2981@umcp-cs.UUCP> Lines: 35 Keywords: Unix, string search, Sake o nomimasu ka? > From: chris@umcp-cs.UUCP (Chris Torek) > $ find / -exec egrep "pattern" {} \; -print 2> /dev/null An excellent answer to the find strings in any file request. I have a few suggestions to add: * if you only want the file names, use '-l' flag with one of the grep variants and you won't have to worry about redirecting stderr and out seperately (you won't need '-print' flag to find) * if you are looking for specific strings, as opposed to regular expressions, use fgrep instead of egrep * to print context, look into "cgrep", posted to net.source a short while back -- it allows you to print m lines before and n lines after each match * you only want to look at files, so add '-type f' to find You end up with: $ find / -type f -exec fgrep -l "string" {} \; > file Some notes: * '/' can be replaced by any directory to search its sub-tree * if you are looking for the same strings at periodic times, you might want to consider keeping a "current" file listing the occurrences, adding '-newer file' to the find command, and appending to the file, thus negating the need to pick up all occurrences every time. Mike O'Shea decvax!mcnc!unccvax!wgivax!mo