如何将Linuxwhich命令的输出通过管道传输到Linux文件命令中?

发布于 2024-10-17 19:36:25 字数 441 浏览 7 评论 0原文

$ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不知在何时 2024-10-24 19:36:25

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

$ which file | xargs file

$ file `which file`

You're probably looking for xargs or shell expansion. Try:

$ which file | xargs file

or

$ file `which file`
鱼窥荷 2024-10-24 19:36:25

file 期望其参数出现在命令行上,而不是其标准输入上,除非您另有说明:

$ which file | file -f -

或者:

$ file `which file`

或者,为了完整起见:

$ which file | xargs file

file expects its arguments on the command line, not on its standard input, unless you tell it otherwise:

$ which file | file -f -

Alternatively:

$ file `which file`

Or, for completeness:

$ which file | xargs file
深海里的那抹蓝 2024-10-24 19:36:25

请尝试使用反引号,例如

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

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

Try backquotes instead, e.g.

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文