Linux命令输出作为另一个命令的参数 [英] Linux command output as a parameter of another command

查看:925
本文介绍了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:

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 name myFile
  • -exec: for the search results, perform additional commands with them
  • cp /home/myuser/myFile {}: copies /home/myuser/myFile to overwrite each result returned by find to ; think of {} as where each search result goes.
  • ';': used to separate different commands to be run after find

这篇关于Linux命令输出作为另一个命令的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆