Need unix command file HELP!
Michael Wescott
wescott at sauron.UUCP
Tue Feb 4 15:41:53 AEST 1986
In article <587 at smeagol.UUCP> earle at smeagol.UUCP (Greg Earle) writes:
>> We are looking for a utility that can, when given a arbitrary string,
>> can locate all occurences of that string anywhere on the system.
>
>find / -exec fgrep this-is-the-string '{}' \; (UGGGHHH!)
>
>Warning! Only execute during hours when no one else is in building!!
>Guaranteed to tie up CPU for indefinite periods! :@)
>
>If you only want the file names, this *might* work, I'm not sure ...
>
>find / -exec "fgrep this-is-the-string '{}' | awk -F: '{print $1}'" \;
>(DOUBLE UGGGHHH)
I agree, UGGHHH. I know its not on most BSD systems, but it has its
uses. I'm talking about `xargs'. For much less cpu usage try:
find / -type f -print | grep -v outfile | xargs grep 'pattern' > outfile
or some reasonable variation with your favorite grep (or bm).
Xargs accumulates arguments from stdin and execs the command and args
given for a reasonable number of collected arguments. Hence grep
gets executed once per ten or twenty files rather than once per file.
I think it's reasonable to expect to search only regular files, hence
"-type f" and you better exclude "outfile" unless you use "grep -l".
-Mike Wescott
ncrcae!wescott
More information about the Comp.unix.wizards
mailing list