user3898993 user3898993 - 1 year ago 131
Linux Question

How to check latest kernel version by bash

How can I check latest kernel version by bash?
Is there any command to check latest kernel from ?

Answer Source

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 | grep -A1 'mainline:' | grep -oP '(?<=strong>).*(?=</strong.*)'

It will return you the 'mainline' release. You can search for 'stable' release using the same logic.


-o Option to print only what matches the pattern.

-P Interpret the pattern as a Perl regular expression.

(?=pattern) A zero-width positive look-ahead assertion. To put it in simple words using an example, q(?=u) matches a q that is followed by a u.

(?<=pattern) A zero-width positive look-behind assertion. 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

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download