【问题标题】:How to pipe the output of the Linux which command into the Linux file command?如何将 Linux which 命令的输出通过管道传输到 Linux 文件命令中?
【发布时间】:2011-06-28 09:23:30
【问题描述】:
$ which file
/usr/bin/file
$ file /usr/bin/file
/usr/bin/file: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped

为什么这不起作用?

$ which file | file

Usage: file [-bcikLhnNrsvz0] [-e test] [-f namefile] [-F separator] [-m magicfiles] file...
   file -C -m magicfiles

请尝试file --help 了解更多信息。

【问题讨论】:

标签: linux file command pipe


【解决方案1】:

您可能正在寻找 xargs 或 shell 扩展。试试:

$ which file | xargs file

$ file `which file`

【讨论】:

    【解决方案2】:

    file 期望它的参数在命令行上,而不是在它的标准输入上,除非你另有说明:

    $ which file | file -f -
    

    或者:

    $ file `which file`
    

    或者,为了完整性:

    $ which file | xargs file
    

    【讨论】:

    • $ 哪个文件 |为完整性添加 xargs 文件选择了此答案,因为它具有最短的管道选项。
    【解决方案3】:

    尝试使用反引号,例如

    $ file `which python`
    /usr/bin/python: symbolic link to `python2.6'
    

    您的示例不起作用,因为您的管道正在将 which 命令的输出发送到 file 命令的标准输入。但文件不适用于标准输入 - 它适用于命令行参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-18
      • 2019-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-18
      • 2012-04-24
      • 1970-01-01
      相关资源
      最近更新 更多