When you are debugging drivers like you do, you may want to know which Linux kernel version your system is using? Here are three ways to check the kernel version in the Linux terminal.

linux

I am using Ubuntu at the time of writing this article, but these commands are generic and can be used on Fedora, Debian, CentOS, SUSE Linux or any other Linux distribution.

Using the uname command to find the Linux kernel version

uname is a Linux command used to get information about your system. You can also use it to determine whether you are using a 32-bit or 64-bit system.

Open a terminal and type the following command.

1
uname -r

The output will be similar to the following.

1
4.4.0-97-generic

This means that you are running Linux kernel 4.4.0-97, or more generally, that you are running Linux kernel version 4.4.

But what do the other numbers here mean?

  • 4 - kernel version
  • 4 - major revision
  • 0 - minor revision
  • 97 - bug fixes
  • generic - A distribution-specific string. For Ubuntu, this means that I am using the desktop version. For Ubuntu server versions, it will be server.

You can also use the uname command with the option -a. This will give you more information about your system if you need it.

1
uname -a

The output of the command should look like this.

1
Linux itsfoss 4.4.0-97-generic #120-Ubuntu SMP Tue Sep 19 17:28:18 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Let me look at the output and what it means.

  • Linux - kernel name. If you run the same command on BSD or macOS, the result will be different.
  • myfreax - The host name.
  • 4.4.0-97-generic - Kernel version (as we saw above).
  • #120-Ubuntu SMP Tue Sep 19 17:28:18 UTC 2017 - This means that Ubuntu has compiled 4.4.0-97-generic 120 times. The timestamp of the last compilation is also there.
  • x86_64 - Machine architecture.
  • x86_64 - Processor architecture.
  • x86_64 - Operating system architecture (you can run a 32-bit operating system on a 64-bit processor).
  • GNU/Linux - operating system.

Let’s look at some other commands to find your Linux kernel version.

Using the /proc/version file to find the Linux kernel

In Linux you can also find kernel information in the file /proc/version. We can take a look at the contents of this file using the cat command.

1
cat /proc/version

You will see output similar to that seen with uname.

1
Linux version 4.4.0-97-generic (buildd@lcy01-33) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #120-Ubuntu SMP Tue Sep 19 17:28:18 UTC 2017

You can view the kernel version 4.4.0-97-generic here.

Using the dmesg command to find the Linux kernel version

dmesg is a powerful command for writing kernel messages. It is also very useful for getting system information.

Since dmesg provides a lot of information, you should normally use a command such as less to read it. However, since we are only here to check the Linux kernel version, grepping on “Linux” should provide the required output.

1
dmesg | grep Linux

The output will be a few lines long, but you should be able to easily identify the Linux kernel version.

1
2
3
4
5
6
7
8
[ 0.000000] Linux version 4.4.0-97-generic (buildd@lcy01-33) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #120-Ubuntu SMP Tue Sep 19 17:28:18 UTC 2017 (Ubuntu 4.4.0-97.120-generic 4.4.87)
[ 0.182880] [Firmware Bug]: ACPI: BIOS _OSI(Linux) query ignored
[ 1.003861] Linux agpgart interface v0.103
[ 1.007875] usb usb1: Manufacturer: Linux 4.4.0-97-generic xhci-hcd
[ 1.009983] usb usb2: Manufacturer: Linux 4.4.0-97-generic xhci-hcd
[ 5.371748] media: Linux media interface: v0.10
[ 5.399948] Linux video capture interface: v2.00
[ 5.651287] VBoxPciLinuxInit

Conclusion

Of the three methods discussed here, uname is the most convenient. Reading /proc/version directly is suitable for use when writing programs. dmesg command this we generally rarely use.