tags:

views:

157

answers:

2

I want to make a list of files of locate's output. I want scp to take the list.

I am not sure about the syntax. My attempt with pseudo-code

locate labra | xargs scp {} [email protected]:~/Desktop/

How can you move the files to the destination?

+1  A: 

Typically, {} is a findism:

find ... -exec cmd {} \;

Where {} is the current file that find is working on.

You can get xargs to behave similar with:

locate labra | xargs -I{} echo {} more arguments

However, you'll quickly notice that it runs the commands multiple times instead of one call to scp.

So in the context of your example:

locate labra | xargs -I{} scp '{}' [email protected]:~/Desktop/

Notice the single quotes around the {} as it'll be useful for paths with spaces in them.

xyld
+1  A: 

xargs normally takes as many arguments it can fit on the command line, but using -I it suddenly only takes one. GNU Parallel http://www.gnu.org/software/parallel/ may be a better solution:

locate labra | parallel -m scp {} [email protected]:~/Desktop/

Since you are looking at scp, may I suggest you also check out rsync?

locate labra | parallel -m rsync -az {} [email protected]:~/Desktop/
Ole Tange