Linux命令输出作为另一个命令的参数 [英] Linux command output as a parameter of another command
本文介绍了Linux命令输出作为另一个命令的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想传递命令的元素的输出列表作为另一个命令的参数。我找到了一些其他页面:
我只想将一个文件复制到调用Linux的每个结果 find
命令。
这里有什么问题?:
find。 -name myFile 2>& 1 | cp / home / myuser / myFile $ 1
感谢
解决方案
这是你想要的:
-name myFile -exec cp / home / myuser / myFile {}';'
细目/解释
-
find
:调用find命令 $ b - 由于没有指定深度标记,因此将递归搜索所有子文件夹
-
-name myFile
:查找显式名为的文件myFile
-
-exec
:对于搜索结果,请执行其他命令 -
cp / home / myuser / myFile {}
:copies/ home / myuser / myFile
覆盖find
to; ${
{}
。 -
';'
:用于分隔要在之后运行的不同命令
I would like to pass the output list of elements of a command as a parameter of another command. I have found some other pages:
- 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
but they seem to be more complex.
I just would like to copy a file to every result of a call to the Linux find
command.
What is wrong here?:
find . -name myFile 2>&1 | cp /home/myuser/myFile $1
Thanks
解决方案
This is what you want:
find . -name myFile -exec cp /home/myuser/myFile {} ';'
A breakdown / explanation of this:
find
: invoking the find command.
: start search from current working directory.- Since no depth flags are specified, this will search recursively for all subfolders
-name myFile
: find files with the explicit namemyFile
-exec
: for the search results, perform additional commands with themcp /home/myuser/myFile {}
: copies/home/myuser/myFile
to overwrite each result returned byfind
to ; think of{}
as where each search result goes.';'
: used to separate different commands to be run afterfind
这篇关于Linux命令输出作为另一个命令的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文