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

nel*_*aro 2 linux command file 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
Run Code Online (Sandbox Code Playgroud)

为什么这不起作用?

$ which file | file

Usage: file [-bcikLhnNrsvz0] [-e test] [-f namefile] [-F separator] [-m magicfiles] file...
   file -C -m magicfiles
Run Code Online (Sandbox Code Playgroud)

尝试file --help获取更多信息.

yan*_*yan 6

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

$ which file | xargs file
Run Code Online (Sandbox Code Playgroud)

要么

$ file `which file`
Run Code Online (Sandbox Code Playgroud)


Tho*_*mas 5

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

$ which file | file -f -
Run Code Online (Sandbox Code Playgroud)

或者:

$ file `which file`
Run Code Online (Sandbox Code Playgroud)

或者,为了完整性:

$ which file | xargs file
Run Code Online (Sandbox Code Playgroud)