help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Fwd: hi, doubt about xargs


From: John Kearney
Subject: [Help-bash] Fwd: hi, doubt about xargs
Date: Mon, 3 Jun 2013 20:51:00 +0200

Sorry I wasn't too clear in my examples. But you explained what I missed.

I missed the significance of + vs ; the rest makes sense now
Thanks.


in xargs I meant -P not -p i.e. run in parallel.




On Mon, Jun 3, 2013 at 8:40 PM, Greg Wooledge <address@hidden> wrote:
On Mon, Jun 03, 2013 at 08:25:30PM +0200, John Kearney wrote:
> As I understand it the default behaviour of find is {} expands to only one
> file name as such
>
> find .  -name '*.txt' -execdir sh -c 'cp "${0}" "${0%.txt}.bak"' {}
> is the same thing? or what am I missing something.

You are definitely missing something.  You MUST end an -exec with either
a ; or +.  If you use ; then find will fork/exec one sh for every file
that it finds.  If you use + then it will bundle up several filenames
and pass them all at once.

In the example above, you'd need to end with ; because your script is
only written to handle one argument.

(Assuming the nonstandard -execdir has the same syntax as -exec.)

> This on the other hand does make sense.
>
> find .  -name '*.txt' -print0 | xargs -n10 -p3 sh -c 'for f; do cp "$f"
> "${f%.txt}.bak"; done' _ {}

In this one, there's an xargs with nonstandard options, and the {} is
an argument of xargs rather than find.  I won't even try to guess what
this does.  (On my HP-UX machine, xargs -p is "Prompt mode: The user is
asked whether to execute command prior to each invocation."  I'm guessing
yours is different.)

(It also looks like you forgot a -0 option to your xargs.)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]