bedtime question : xargs

Roger Oberholtzer roger at opq.se
Thu Apr 23 04:27:26 PDT 2009


On Thu, 2009-04-23 at 06:18 -0500, David A. Bandel wrote:
> On Wed, Apr 22, 2009 at 10:59 PM, Vu Pham <vu at sivell.com> wrote:
> > Using xargs, how can I pipe the output ( of some command ) as the *first*
> > parameter of some other command ?
> >
> > Here is my problem: I have various rpm files in a directory tree. I want to
> > copy all of these files to a remote server using scp. What I am thinking is
> >
> > [oliver at xen2vm4 redhat]$ find . -name "*.rpm"
> > ./SRPMS/hello-1.0.0-2.src.rpm
> > ./SRPMS/hello-1.0.0-1.src.rpm
> > ./RPMS/i686/hello-1.0.0-2.i686.rpm
> > ./RPMS/i686/hello-1.0.0-1.i686.rpm
> >
> >
> > # find . -name "*.rpm" | xargs  scp  ???   root at remoteserver:
> 
> why invoke xargs at all?
> find . -name \*.rpm -exec scp {} root at remoteserver: \;
> (note:  the \; is required)

That was going to be my first response. But that would do the command
for each file, one at a time. xargs will collect all of then and send
them out as one list in {}, so the command happens once. If there is a
password for the command, this could save a lot of typing...

-- 
Roger Oberholtzer

OPQ Systems / Ramböll RST

Ramböll Sverige AB
Krukmakargatan 21
P.O. Box 17009
SE-104 62 Stockholm, Sweden

Office: Int +46 8-615 60 20
Mobile: Int +46 70-815 1696




More information about the Linux-users mailing list