简体   繁体   English

如何通过bash检查最新的内核版本

[英]How to check latest kernel version by bash

How can I check latest kernel version by bash?如何通过 bash 检查最新的内核版本? Is there any command to check latest kernel from https://www.kernel.org/ ?是否有任何命令可以从https://www.kernel.org/检查最新内核?

If you are looking for the latest kernel version on the website and not the one on your system, you can use this command.如果您正在网站上寻找最新的内核版本而不是您系统上的内核版本,则可以使用此命令。 It will work fine unless they change their page layout later.除非他们稍后更改页面布局,否则它将正常工作。 If they do, in that case, you will have to tweak your command:如果他们这样做,在这种情况下,您将不得不调整您的命令:

[root@slave2 gc]# curl -s https://www.kernel.org/ | grep -A1 'mainline:' | grep -oP '(?<=strong>).*(?=</strong.*)'
            3.16-rc7

It will return you the 'mainline' release.它将返回“主线”版本。 You can search for 'stable' release using the same logic.您可以使用相同的逻辑搜索“稳定”版本。

Explanation:解释:

-o Option to print only what matches the pattern. -o仅打印与模式匹配的选项。

-P Interpret the pattern as a Perl regular expression. -P将模式解释为 Perl 正则表达式。

(?=pattern) A zero-width positive look-ahead assertion. (?=pattern)零宽度正先行断言。 To put it in simple words using an example, q(?=u) matches aq that is followed by a u.举个例子,用简单的话来说, q(?=u)匹配后面跟有 u 的aq

(?<=pattern) A zero-width positive look-behind assertion. (?<=pattern)零宽度正后视断言。 To put it in simple words using an example, (?<=a)b matches the b (and only the b) in cab, but does not match bed or debt举个例子,简单来说, (?<=a)b匹配cab中的 b (并且仅匹配b),但不匹配 Bed 或 Debt

So, whatever pattern is matched is actually removed from the output and that's how we get the result.因此,任何匹配的模式实际上都会从输出中删除,这就是我们获得结果的方式。 :) :)

You can refer these links for more detail:您可以参考这些链接了解更多详情:
http://perldoc.perl.org/perlre.html#Extended-Patterns http://perldoc.perl.org/perlre.html#Extended-Patterns
http://www.regular-expressions.info/lookaround.html http://www.regular-expressions.info/lookaround.html

从 2017 年开始工作

curl -s https://www.kernel.org | grep -A1 latest_link | tail -n1 | egrep -o '>[^<]+' | egrep -o '[^>]+'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM