xargs jar tvf - 不起作用
目标:列出所有 jar 中的文件。
这有效:
for f in `find . -name "*.jar"`; do jar tvf $f; done
这也有效:
find . -name "*.jar" -exec jar tvf {} \;
这不起作用(它不打印任何输出):
find . -name "*.jar" | xargs jar tvf
为什么后者不起作用?
Objective: to list files in all jars.
This works:
for f in `find . -name "*.jar"`; do jar tvf $f; done
This works too:
find . -name "*.jar" -exec jar tvf {} \;
This does not (it does not print any output):
find . -name "*.jar" | xargs jar tvf
Why does the latter not work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这有效吗
Does this works
问题是
jar tvf
只允许传入一个文件。for循环会逐个运行文件
。但是,xargs 尝试在一行中容纳尽可能多的参数。因此,它正在尝试以下操作:
您可以通过在命令中放置 echo 来验证这一点:
正确的解决方案是告诉 xargs 每个命令仅使用一个参数:
或
The problem is that
jar tvf
only allows one file to be passed in.The for loop runs the files one by one
However, xargs tries to fit as many arguments on one line as possible. Thus it's trying the following:
You can verify this by placing an echo in your command:
The proper solution is the tell xargs to only use one parameter per command:
or
它不起作用,因为 xargs 仅调用一个具有所有参数的进程。
有一种方法可以使用
-I'{}'
为每个参数调用一个新进程。试试这个来理解:
It does not work because xargs invoke only one process with all arguments.
There is a way to invoke a new process for each argument using
-I'{}'
.Try this to understand: