【问题标题】:How would you redirect the output of a command into the input of another command您如何将命令的输出重定向到另一个命令的输入
【发布时间】:2018-01-21 02:57:11
【问题描述】:

如何将命令(如 ls)的输出重定向到另一个命令(如 grep)的输入。

换句话说: 下面的空白处会是什么?

$ ls /etc ____ grep host #

【问题讨论】:

标签: shell unix pipe


【解决方案1】:

您可以使用管道| 字符。

你的命令会变成:ls /etc | grep host #

【讨论】:

    【解决方案2】:

    这称为管道,您只需在该位置使用|

    ls /etc | grep host
    

    返回:

    hosts
    hosts.equiv
    hosts-orig    
    

    另一个例子:

    cat /etc/hosts | grep 127
    

    回报(对我而言):

    #127.0.0.1  google.ca
    127.0.0.1   localhost
    

    【讨论】:

      猜你喜欢
      • 2013-01-12
      • 1970-01-01
      • 2010-09-09
      • 2010-11-28
      • 2013-11-08
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      相关资源
      最近更新 更多