Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
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 - Fatal编程技术网

Linux 如何在bash中使用xargs命令检查版本? 请考虑以下情况: $ find / -type f -name httpd /opt/httpd.bin/httpd /etc/rc.d/init.d/httpd /usr/sbin/httpd ......

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

我想使用-version选项检查每个结果,如:

/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的意思,其中一些文件可能不可执行