Linux命令输出作为另一个命令的参数

Linux命令输出作为另一个命令的参数,第1张

概述我想将命令元素的输出列表作为另一个命令的参数传递.我找到了一些其他页面: > How to display the output of a Linux command on stdout and also pipe it to another command? > Use output of bash command (with pipe) as a parameter for another c 我想将命令元素的输出列表作为另一个命令的参数传递.我找到了一些其他页面:

> How to display the output of a Linux command on stdout and also pipe it to another command?
> Use output of bash command (with pipe) as a parameter for another command

但它们似乎更复杂.

我只想将一个文件复制到调用linux find命令的每个结果中.

这里有什么问题?:

find . -name myfile 2>&1 | cp /home/myuser/myfile 

谢谢

解决方法 这就是你想要的:
find . -name myfile -exec cp /home/myuser/myfile {} ';'

对此的细分/解释:

> find:调用find命令>.:从当前工作目录开始搜索.>由于未指定深度标志,因此将以递归方式搜索所有子文件夹> -name myfile:查找显式名称为myfile的文件> -exec:对于搜索结果,使用它们执行其他命令> cp / home / myuser / myfile {}:copy / home / myuser / myfile覆盖find返回的每个结果;将{}视为每个搜索结果的位置.>’;’:用于分隔查找后运行的不同命令

总结

以上是内存溢出为你收集整理的Linux命令输出作为另一个命令的参数全部内容,希望文章能够帮你解决Linux命令输出作为另一个命令的参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1047976.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存