[Trilug-ontopic] [bash] copying `find`ed files across network

Thomas Gardner tmg at pobox.com
Wed May 23 19:52:09 EDT 2012

Oh, yeah.  I guess a solution might be a good idea, too:  I don't see
why instead of trying to do a:

  tar cfvz - $(find | grep)

on the remote end, a:

  find | grep | xargs tar cfvz -

on the remote end wouldn't work.  Kinda where you started, but I think
it was really dump and restore giving you trouble before, wasn't it?
I forget.

BTW, I'm thinking you could probably also use the ``--exclude=PATTERN''
option to tar instead of the finding and grepping to get the same
effect, unless it isn't GNU tar on the other end, but then again I
haven't thought about it real hard yet (and thinkin' ain't always
my strong suit anyway).

As a side note, I generaly don't like:

  find | xargs

without using ``-print0'' and ``-0'' on the find and xargs comands
respectively.  Even if you think there are no filenames in the
directory that have spaces tabs or newlines, well, I've seen people
be surprised before....  In this case you had a grep in between,
but that also has ``-Z'' and ``-z'' options for that.


On 5/23/12, Thomas Gardner <tmg at pobox.com> wrote:
> On 5/23/12, Tom Roche <Tom_Roche at pobox.com> wrote:
>> [...]
> (Rearranging the order of your original note a little, sorry):
>> Why is the raw `find` working, but the same `find` inside `tar` draws
>> the 'empty archive' warning (presumably due to *not* finding the files)?
> It's a little hard to tell for sure what's really going on because
> of all the indirection you've got going on in your script, but if
> you only look at the command that is being printed before execution
> (which may or may not be exactly what's really being executed ---
> quoting is always a little tricky that way) this:
>> # case 2: `find` inside `tar`
>> * $ ssh t "pushd /work/MOD3EVAL/nsu/boundary/BLD_ddm_saprc07tc ; tar cfvz
>> -
>> $(find . -type f | grep -ve 'CCTM\|CVS\|~$\|\.o$')" | tar xvfz -
> has quoting issues.  Things like $variable, `command argument` and
> $(command argument) are not protected by double quotes.  In other
> words, they get evaluated before the command is ever even run.
> Therefore, I think that ``find'' is actually running on your local
> machine before the ssh process ever starts.
> On the other hand, this:
>> # case 1: `raw find`
>> * $ ssh t "pushd /work/MOD3EVAL/nsu/boundary/BLD_ddm_saprc07tc ; find .
>> -type f | grep -ve 'CCTM\|CVS\|~$\|\.o$' | wc -l"
>> * /work/MOD3EVAL/nsu/boundary/BLD_ddm_saprc07tc ~
>> * 266
> doesn't try to protect any embedded commands or variables within the
> command from command line evaluation (no $(command arg) or `command
> arg` stuff going on in there) .
> Make sense?  I'm not always good at explaining this stuff...
> tg.

More information about the Trilug-ontopic mailing list