Operating System - HP-UX
1830031 Members
2501 Online
109998 Solutions
New Discussion

find -exec terminated by "+"

 
Graham Cameron_1
Honored Contributor

find -exec terminated by "+"

Doesn't work for me as the manual says it should. Is it me or do I log a bug with HP ?

#uname -a
HP-UX moriston B.11.11 U 9000/800 639309331 unlimited-user license
#find . -name \*sql -exec grep -il gl_data {} \;
./11325/chg_mine.sql
./11325/code/sp_hkeep_gl_data.sql
./11325/code_11325.sql
#find . -name \*sql -exec grep -il gl_data {} \+

--Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
15 REPLIES 15
Graham Cameron_1
Honored Contributor

Re: find -exec terminated by "+"

Apologies - lost in my cut and paste - the final find returned nothing !!
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Robin Wakefield
Honored Contributor

Re: find -exec terminated by "+"

Hi Graham,

Which manual was this in? I've never seen this syntax before.

rgds, Robin
Pete Randall
Outstanding Contributor

Re: find -exec terminated by "+"

On 11.11, man find gives:
-exec cmd True if the executed cmd returns a zero value
as exit status. The end of cmd must be
punctuated by a semicolon (;) or a plus sign
(+) (semicolon and plus are special to the
shell and must be escaped). When a plus sign
is used, cmd aggregates a set of pathnames
and executes on the set. The reason for
preferring + to a semicolon is vastly
improved performance. Any command argument
{} is replaced by the current path name. cmd
may contain supplementary code set
characters.


I've tried this myself and never even gotten a prompt back - had to c to get out of it.

Pete

Pete
Pete Randall
Outstanding Contributor

Re: find -exec terminated by "+"

11.0, too!

Pete
Ian Lochray
Respected Contributor

Re: find -exec terminated by "+"

Very strange. If I have the files /tmp/ian1/ian11 and /tmp/ian2/ian12 I get the following results:
find /tmp -name ian\* -exec ls -d {} \+

/tmp/ian1:
ian11

/tmp/ian1/ian11:

/tmp/ian2:
ian12

/tmp/ian2/ian12:

find /tmp -name ian\* -exec ls {} \+
returns nothing.
Darren Prior
Honored Contributor

Re: find -exec terminated by "+"

Hi Graham,

Can you humour me and try running your command as follows:

#find . -name \*sql -exec grep -il gl_data gl_data {} \+

ie, adding an extra gl_data and letting me know if it works.

regards,

Darren.
Calm down. It's only ones and zeros...
Pete Randall
Outstanding Contributor

Re: find -exec terminated by "+"

Darren,

That seems to work (but is counter-intuitive, to say the least).

Pete

Pete
Leif Halvarsson_2
Honored Contributor

Re: find -exec terminated by "+"

Hi
Look at the following:

# find /tmp -name 'aa*' -exec ls {} \+

# find /tmp -name 'aa*' -exec ls \+
/tmp/aaa

# find /tmp -name 'aa*' -exec ls {} \;
/tmp/aaa



# find /tmp -name 'aa*' -exec ls \;
#UNTITLED# .rhosts dead_letter sent.mail
#aaa# .sh_history dev stand
-y .shrc dtdbcache_c153:0 testmenu
.ICEauthority .sw etc tmp
.TTauthority .windu.c165 export tmp_mnt
.WindU .xsession home tmpfile
.Xauthority aax lib usr
.cshrc ansys_inc lost+found var
.dt bin mbox xaa
.dtprofile cd omnisv.log xxx
.gpmhp-c165 cma_dump.log opt ??3??3@^
.profile core print_info
.pvprinters_ver1 daytasks sbin



Graham Cameron_1
Honored Contributor

Re: find -exec terminated by "+"

Darren's suggestion helps, but why ?

Also it doesn't seem to matter what goes into the repeated field, so long as there's something there ....

#find . -name \*sql -exec grep -il gl_data gl_data {} \+
./11325/chg_mine.sql
./11325/code/sp_hkeep_gl_data.sql
./11325/code_11325.sql
#find . -name \*sql -exec grep -il gl_data rubbish {} \+
./11325/chg_mine.sql
./11325/code/sp_hkeep_gl_data.sql
./11325/code_11325.sql
#find . -name \*sql -exec grep -il rubbish gl_data {} \+
#
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Leif Halvarsson_2
Honored Contributor

Re: find -exec terminated by "+"

Hi,

I have made some mor trials.

# find /tmp -name 'aa*' -exec ls {} \;
/tmp/aaa
/tmp/aax
/tmp/aay
# find /tmp -name 'aa*' -exec ls \+
/tmp/aaa /tmp/aax /tmp/aay

It seems as the difference is
This syntax:
find /tmp -name 'aa*' -exec ls {} \;
Result:
ls /tmp/aaa
ls /tmp/aax
ls /tmp/aay

And this syntax:
find /tmp -name 'aa*' -exec ls \+
Result:
ls /tmp/aaa /tmp/aax /tmp/aay

Darren Prior
Honored Contributor

Re: find -exec terminated by "+"

Hi Graham,

Thanks for humouring me; I've done some further checking into this for you. There's definitely a "feature" in find -exec.

The workaround is to put a junk argument before the braces - as you've seen. If you're interested in getting a fix for this please log a call with your local HP Response Centre and quote the following SR number: 5003435560. I have to state the usual stuff, that we cannot offer timescales for fixes, or guarantee that a fix will be written.

regards,

Darren.
Calm down. It's only ones and zeros...
Graham Cameron_1
Honored Contributor

Re: find -exec terminated by "+"

Thanks Darren, for confirming what we'd more or less deduced.
For now I'll live with the ";" terminator in preference to the "+", in spite of it being inefficient.

And thanks to all other contributors.

--Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Pete Randall
Outstanding Contributor

Re: find -exec terminated by "+"

Graham,

Isn't this the same thing as using xargs? I'm quoting James' comments from this thread:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xc5620fe6d0f7d61190050090279cd0f9,00.html

====quote====
A 'find' piped to 'xargs' is kinder to your system then a 'find ... -exec'. With '-exec' a new task is spawned for every file to remove. With 'xargs', a large group of files names can be buffered and a single task for that group spawned. For example:

# cd
# find . -type f -print|xargs -n500 rm {}

Regards!

...JRF...
===unquote===


Pete

Pete
Graham Cameron_1
Honored Contributor

Re: find -exec terminated by "+"

Pete

Yes it's exactly the same as xargs, just a simpler syntax to remember (if it worked).

--Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Pete Randall
Outstanding Contributor

Re: find -exec terminated by "+"

Graham,

Agreed.


Pete

Pete