Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get only part of uname -r in bash

I need to get only first two numbers of "uname -r" command in bash

example of regular out put:

uname -r
3.5.0-18-generic

what I expect using magic bash options:

3.5
like image 326
Ba7a7chy Avatar asked Dec 10 '25 13:12

Ba7a7chy


1 Answers

assuming you want everything before the second dot, this will do what you want:

uname -r | cut -d. -f1-2

uname itself does not support cutting the output, afaik. The pipe through cut will show you fields 1 and 2 (-f1-2), delimited by dots (-d.)

like image 184
Yefim Dinitz Avatar answered Dec 12 '25 07:12

Yefim Dinitz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!