![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
+ instead of ;
Code:
find . -name \*.txt -exec grep -i "ZMA" {} \+
Is it even slightly portable to other unixen? It doesn't work on RH 7.2, does on HPUX, for example. |
| Forum Sponsor | ||
|
|
|
||||
|
The performance gain is similar to the xargs trick.
In addition to saving one more process, this + notation has another advantage over xargs. xargs reads file names from standard input, one name per line. This means that xargs will break if a file name has an embedded newline character. It's not possible to construct a filename that will break the + notation. The + sign is part of the posix standard. But I think it's a recent addition. |
|
|||
|
With regard to the performance issue -
Calling find with a semi-colon results in thousands of fork() calls, calling with the plus sign results in one fork() - that lasts a fairly long time as grep runs over thousands of files. Which is why we started using it. But we have lots of linux boxes that don't support fully POSIX-compliant find I suppose. Which results in two versions of scripts that call find like this - a bad thing. I'm going to go back and something about it, but I wanted to know what I was up against. Thanks. |
|
|||
|
We had xargs, I wanted to try + and see if things improved.
For what I was doing, basically reading the entire filesystem, + did seem to work better. So, I tried it on Linux and hit a problem. Back to square 1. |
|||
| Google UNIX.COM |