linux - 如何在 bash 中使用 xargs 命令检查版本?

标签 linux bash shell 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命令,这可行吗? 非常感谢。

最佳答案

xargs 并不是真正适合这项工作的工具,但 for 循环可以工作:

for httpd in $(find / -type f -name httpd)
do
    $httpd --version
done

如果您有数千个 httpd,那么您可能会遇到 $(find...) 输出的长度问题,但您可能会遇到更大的问题如果你有那么多 httpd,你的手。

关于linux - 如何在 bash 中使用 xargs 命令检查版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7510256/

相关文章:

linux - 在 Linux 上创建核心转储

linux - USB调制解调器的交叉编译驱动程序

linux - 服务不支持 chkconfig

bash - 在 shUnit2 中重定向文件输出的单元测试 bash 脚本

linux - 创建脚本以在 linux 中使用变量运行多个命令

linux - 无法从 bash 脚本中获取带有空格的路径?

linux - 在 ubuntu 中创建别名,在 .profile 中

python - 如何将Python包从旧版本安装到新版本?

shell - 带有字符串前缀和后缀的 Unix 行到列格式

Php/Perl/Python/Shell 脚本根据某些字符的存在来重命名文件