|
From: | John Kearney |
Subject: | [Help-bash] Fwd: hi, doubt about xargs |
Date: | Mon, 3 Jun 2013 20:51:00 +0200 |
On Mon, Jun 03, 2013 at 08:25:30PM +0200, John Kearney wrote:You are definitely missing something. You MUST end an -exec with either
> 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.
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.)
In this one, there's an xargs with nonstandard options, and the {} is
> 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' _ {}
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.)
[Prev in Thread] | Current Thread | [Next in Thread] |