The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-04-2004
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
+ 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.
Reply With Quote
Forum Sponsor
  #2  
Old 08-04-2004
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
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
Reply With Quote
  #3  
Old 08-04-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
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.
Reply With Quote
  #4  
Old 08-04-2004
kduffin's Avatar
UN1X
 

Join Date: Nov 2003
Location: Virginia
Posts: 441
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
Reply With Quote
  #5  
Old 08-05-2004
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
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.
Reply With Quote
  #6  
Old 08-05-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
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.
Reply With Quote
  #7  
Old 08-05-2004
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0