Question

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 {} masi@11.11.11:~/Desktop/

How can you move the files to the destination?

Was it helpful?

Solution

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 '{}' masi@11.11.11:~/Desktop/

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

OTHER TIPS

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 {} masi@11.11.11:~/Desktop/

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

locate labra | parallel -m rsync -az {} masi@11.11.11:~/Desktop/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top