Linux命令输出作为另一个命令的参数
发布时间:2020-12-13 19:26:31 所属栏目:Linux 来源:网络整理
导读:我想将命令元素的输出列表作为另一个命令的参数传递.我找到了一些其他页面: 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
我想将命令元素的输出列表作为另一个命令的参数传递.我找到了一些其他页面:
> How to display the output of a Linux command on stdout and also pipe it to another command? 但它们似乎更复杂. 我只想将一个文件复制到调用Linux find命令的每个结果中. 这里有什么问题?: find . -name myFile 2>&1 | cp /home/myuser/myFile $1 谢谢 解决方法
这就是你想要的:
find . -name myFile -exec cp /home/myuser/myFile {} ';' 对此的细分/解释: > find:调用find命令>.:从当前工作目录开始搜索.>由于未指定深度标志,因此将以递归方式搜索所有子文件夹> -name myFile:查找显式名称为myFile的文件> -exec:对于搜索结果,使用它们执行其他命令> cp / home / myuser / myFile {}:copy / home / myuser / myFile覆盖find返回的每个结果;将{}视为每个搜索结果的位置.>’;’:用于分隔查找后运行的不同命令 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |