Linux 如何在bash中使用xargs命令检查版本? 请考虑以下情况: $ find / -type f -name httpd /opt/httpd.bin/httpd /etc/rc.d/init.d/httpd /usr/sbin/httpd ......
我想使用-version选项检查每个结果,如:Linux 如何在bash中使用xargs命令检查版本? 请考虑以下情况: $ find / -type f -name httpd /opt/httpd.bin/httpd /etc/rc.d/init.d/httpd /usr/sbin/httpd ......,linux,bash,shell,xargs,Linux,Bash,Shell,Xargs,我想使用-version选项检查每个结果,如: /usr/sbin/httpd -version 但是我不能编写xargs命令,它可行吗? 非常感谢。xargs并不是这项工作的正确工具,但是for循环可以: for httpd in $(find / -type f -name httpd) do $httpd --version done 如果您有数千个httpds,那么您可能会遇到$(find…输出长度的问题,但是如果您有那么多httpds,您可能会遇到更大的问题。您可以使用xa
/usr/sbin/httpd -version
但是我不能编写xargs命令,它可行吗?
非常感谢。
xargs
并不是这项工作的正确工具,但是for
循环可以:
for httpd in $(find / -type f -name httpd)
do
$httpd --version
done
如果您有数千个
httpd
s,那么您可能会遇到$(find…
输出长度的问题,但是如果您有那么多httpd
s,您可能会遇到更大的问题。您可以使用xargs检查如下版本:
find ./ -type f -name httpd | xargs -n1 -I{} bash -c "{} --version"
但我不推荐,这很麻烦
您可以使用:
find ./ -type f -name httpd -exec {} --version \; -print
(可选打印)
另一方面,请确保确实要执行这些文件,/etc/rc.d/init.d/httpd可能不知道--version的意思,其中一些文件可能不可执行