如何在 bash 中使用 xargs 命令检查版本?
请考虑以下场景:
$ find / -type f -name httpd
/opt/httpd.bin/httpd
/etc/rc.d/init.d/httpd
/usr/sbin/httpd
......
我想使用 -version 选项检查每个结果,例如:
/usr/sbin/httpd -version
但我无法编写 xargs 命令,这可行吗? 非常感谢。
Please consider the following scenario:
$ find / -type f -name httpd
/opt/httpd.bin/httpd
/etc/rc.d/init.d/httpd
/usr/sbin/httpd
......
I'd like to check each and everyone of the results using the -version option like:
/usr/sbin/httpd -version
But I cannot write the xargs command, is it feasible?
Many thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 xargs 来检查版本,如下所示:
但我不建议这样做,这很麻烦
您可以使用:(
打印是可选的)
顺便说一句,请确保您确实想要执行所有文件, /etc/ rc.d/init.d/httpd 可能不知道 --version 是什么意思,其中一些可能无法执行。
You can use xargs to check the version like this:
But I would not recommended, it's cumbersome
You can use:
(with print being optional)
On a side note, make sure that you really want to execute those all the files, /etc/rc.d/init.d/httpd may not know what --version means, some of them may not be executable.
xargs
并不是真正适合这项工作的工具,但是for
循环可以工作:如果您有数千个
httpd
那么您可能会遇到了$(find...)
输出的长度问题,但如果您有那么多httpd
,您可能遇到更大的问题。xargs
isn't really the right tool for the job, afor
loop would work though:If you have thousands of
httpd
s then you might run into a problem with the length of the$(find...)
output but you probably bigger problems on your hands if you have that manyhttpd
s.