scp 通过 Xargs 定位输出

发布于 2024-08-11 00:08:52 字数 297 浏览 2 评论 0原文

我想制作一个locate 输出的文件列表。 我想要 scp 获取该列表。

我不确定语法。 我对伪代码的尝试

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

如何将文件移动到目的地?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

是你 2024-08-18 00:08:52

xargs 通常会接受命令行中能够容纳的尽可能多的参数,但是使用 -I 它突然只需要一个。 GNU Parallel http://www.gnu.org/software/parallel/ 可能是更好的解决方案:

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

既然您正在查看 scp,我可以建议您也查看一下 rsync 吗?

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

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/
栀子花开つ 2024-08-18 00:08:52

通常,{} 是查找主义:

find ... -exec cmd {} \;

其中 {} 是查找正在处理的当前文件。

您可以使 xargs 的行为类似于:

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

但是,您很快就会注意到它多次运行命令,而不是一次调用 scp

因此,在您的示例的上下文中:

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

请注意 {} 周围的单引号,因为它对于其中包含空格的路径很有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文