如何将Linux which命令的输出传递给Linux文件命令?

时间:2011-02-16 14:02:38

标签: linux file command pipe which

$ 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了解详情。

3 个答案:

答案 0 :(得分:6)

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

$ which file | xargs file

$ file `which file`

答案 1 :(得分:5)

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

$ which file | file -f -

可替换地:

$ file `which file`

或者,为了完整性:

$ which file | xargs file

答案 2 :(得分:4)

请尝试反引号,例如

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

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

相关问题