Need unix command file HELP!

mo at wgivax.UUCP mo at wgivax.UUCP
Mon Feb 3 00:43:44 AEST 1986


> From: chris at 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



More information about the Comp.unix mailing list