[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] hi, doubt about xargs
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] hi, doubt about xargs |
Date: |
Mon, 3 Jun 2013 14:40:48 -0400 |
User-agent: |
Mutt/1.4.2.3i |
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.)