我正在寻找一种对Red Hat 6服务器上的所有rt.jar进行扫描的方法,然后找出在每个目录中使用的Java版本。我有时会注意到,如果该目录未在我迷路的文件夹中列出该版本。我假设我可以使用'sudo find / -name rt.jar'查找所有rt.jar,但是如何检查这些rt.jar文件的每个Java版本?
Example :
[admin:/ryan/vacation-linux/bin]
(admin)$ sudo find / -name rt.jar
/ryan/jre1.8.0_171_linux/lib/rt.jar
/bob/jre1.6.0_171_linux/lib/rt.jar
/charles/java/lib/rt.jar
谢谢, 瑞安
答案 0 :(得分:1)
结合使用find
和awk
来生成java -version
命令以运行:
sudo find /Library/Java/JavaVirtualMachines -name rt.jar | awk -v OFS='/' -F '/' '{$(NF)="" ; printf("echo %s && %s../bin/java -version && echo && echo\n", $0, $0)}' | sh
对我来说,它打印:
/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home/jre/lib/
java version "1.8.0_141"
Java(TM) SE Runtime Environment (build 1.8.0_141-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.141-b15, mixed mode)
/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)