+ instead of ;


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting + instead of ;
# 1  
Old 08-04-2004
+ instead of ;

Code:
 find . -name \*.txt -exec grep -i "ZMA" {} \+

using the plus sign is better for performance, according to the manpage on find. Works fine.

Is it even slightly portable to other unixen? It doesn't work on RH 7.2, does on HPUX, for example.
# 2  
Old 08-04-2004
Well, it works under Solaris 9.

Doesn't work under Cygwin (uses GNU find), and doesn't work under SuSE 8.2 (also uses GNU find) or RH9.

They're the only systems I have to hand at home at the moment.

Cheers
ZB
# 3  
Old 08-04-2004
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.
# 4  
Old 08-04-2004
As Perderabo stated, it is a recent addition. It was added in the SUSv3, IEEE 1003.1-200x although it originates from SVR4:
It has been implemented and documented on UnixWare at least since 2.1. It has been implemented in all SunOS 5.x versions, but is only documented since SunOS 5.9. So you can use it even though the man pages don't list it. It has been implemented and documented in HP-UX since 11.x. IRIX (up to 6.5.15) in contrast doesn't provide it, its find(1) apparently originates from SVR3.

Cheers,

Keith
# 5  
Old 08-05-2004
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.
# 6  
Old 08-05-2004
Jim, you will not be able to measure the trivial performance difference between using the plus sign notation and using xargs. And xargs has been around for a long time and should be very portable.
# 7  
Old 08-05-2004
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.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question