1 |
On Tuesday 9 June 2009, 16:36, Neil Bothwick wrote: |
2 |
> On Tue, 09 Jun 2009 16:15:21 +0200, Joerg Schilling wrote: |
3 |
> > > find -H /usr/lib /lib -type f | xargs -d'\n' qfile --orphans |
4 |
> > |
5 |
> > No, this is definitely wrong: the right way to handle this is |
6 |
> > execplus (since 19 years). |
7 |
> |
8 |
> If it's been around 19 years, why doesn't Google know anything about |
9 |
> it? What is it? |
10 |
|
11 |
Well, google does not know everything :) |
12 |
|
13 |
Basically, using + instead of ; after -exec allows to run the specified |
14 |
command less times, each time with the highest possible number of |
15 |
arguments (instead of running it once per file, which is what happens |
16 |
with ;). And yes, that's been in POSIX for a long time now. Example: |
17 |
|
18 |
|
19 |
$ ls |
20 |
file1 file2 file3 file4 file5 |
21 |
|
22 |
$ find . -type f -exec sh -c 'echo "number of arguments: $#"' sh {} \; |
23 |
number of arguments: 1 |
24 |
number of arguments: 1 |
25 |
number of arguments: 1 |
26 |
number of arguments: 1 |
27 |
number of arguments: 1 |
28 |
|
29 |
$ find . -type f -exec sh -c 'echo "number of arguments: $#"' sh {} + |
30 |
number of arguments: 5 |
31 |
|
32 |
So when you have to run a command on a very big number of files, say 1000 |
33 |
or more, with ; you spawn 1000 processes, with + you span just one or |
34 |
two (well, depending on the maximum command line length on the system |
35 |
anyway). This is of course much less resource intensive. |
36 |
|
37 |
Basically, using -exec with + does what xargs does, but without the need |
38 |
to care for strange characters in file names (well, a bit simplified, |
39 |
but you get the idea). |