繁体   English   中英

如何将 Linux which 命令的输出通过管道传输到 Linux file 命令中?

[英]How to pipe the output of the Linux which command into the Linux file command?

$ 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以获取更多信息。

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

$ which file | xargs file

或者

$ file `which file`

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

$ which file | file -f -

或者:

$ file `which file`

或者,为了完整性:

$ which file | xargs file

尝试反引号,例如

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM