如何将Linuxwhich命令的输出通过管道传输到Linux文件命令中?
$ 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
了解更多信息。
$ 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
Why does this not work?
$ which file | file
Usage: file [-bcikLhnNrsvz0] [-e test] [-f namefile] [-F separator] [-m magicfiles] file...
file -C -m magicfiles
Try file --help
for more information.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能正在寻找 xargs 或 shell 扩展。尝试:
或
You're probably looking for xargs or shell expansion. Try:
or
file
期望其参数出现在命令行上,而不是其标准输入上,除非您另有说明:或者:
或者,为了完整起见:
file
expects its arguments on the command line, not on its standard input, unless you tell it otherwise:Alternatively:
Or, for completeness:
请尝试使用反引号,例如
您的示例不起作用,因为您的管道正在将 which 命令的输出发送到 file 命令的标准输入。但 file 不适用于标准输入 - 它适用于命令行参数。
Try backquotes instead, e.g.
Your example doesn't work because your pipe is sending the output of the which command to the stdin of the file command. But file doesn't work on stdin - it works on a command line argument.