0

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?

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

2 Answers2

3

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/
Ole Tange
  • 31,768
  • 5
  • 86
  • 104
1

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.

dlamotte
  • 6,145
  • 4
  • 31
  • 40
  • downvote because you mention the problem that `xargs` will call `scp` one time for every input file but there's no solution. As the question is explicitly about using `scp` I'd expect that. Also you recommend using single quotes like `'{}'`--the quotes are eaten by your shell and make no difference at all. – Daniel Böhmer Oct 23 '14 at 13:11