how to find the os version in linux from command line

Linux and Unix operating systems comes in a wide range of flavors often bundled as different distributions by different vendors. Every one of these distributions also comes with an often particular version of the Linux kernel. Mostly it is a latest version of the kernel, but you would want to check the kernel version to see how up to date it is.

When you need to know the exact name and version of your operating system, as well as the kernel, there are several different ways to do it. There are some common reasons why you might want to check your OS version, it might be it to install the correct version of a software, find if a hardware is compatible or be it to upgrade your OS itself.

As I mentioned, there are several ways to find your operating system and Linux kernel versions. As each distribution (or distros) is slightly different some of these commands might work only in certain distros.


uname is the Linux command which prints out the name, OS versions and other details of the machine and kernel running on the machine. It is basically short for Unix Name. This is usually part of the core-utils package and should be available on almost all distros. There are several options available to print out just the kernel details or just the machine information.

To print out just the kernel information, use the -srv option. It prints out all the available kernel information.

bash$ uname -srv
Linux 3.3.0-gentoo #2 SMP PREEMPT Wed Mar 21 02:07:10 CDT 2012

The first part prints out the kernel name, which is Linux in the above example. The second part is the kernel release version, which is 3.3.0-gentoo. The rest of it is a more detailed kernel information like the compilation date and config.

To print out the machine information, use the -mnipo options.

bash$ uname -mnipo
machinename i686 Intel(R) Core(TM)2 Duo CPU E6850 @ 3.00GHz GenuineIntel GNU/Linux

machinename is the name of the machine, while the rest is the processor architecture, processor type, version, speed and operating system information.

You can also use the -a option which prints out all the available information about the kernel and the machine.


Another command to check the os version is the hostnamectl command. This is a handy command that can be used to query and modify the system hostname and other related settings.

bash$ hostnamectl


Static hostname: borgen
Icon name: computer-desktop
Chassis: desktop
Machine ID: 3467dffddf9247cda64a3f684571c7c4
Boot ID: 55e62de550c9400384776c8501d41f07
Operating System: Sabayon/Linux
Kernel: Linux 4.18.0-sabayon
Architecture: x86-64

As you can see, the hostnamectl command will pretty print the os version and other related information. You can find the operating system, the architecture and kernel versions quite easily.

/etc/release and OS version files

Some distributions ships with a separate set of files which specify the release and versions of the distro. These files are usually in the /etc folder with either the word release or version in them. You can view these files using any text editor or the cat command.

bash$ cat /etc/*-release*
Gentoo Base System release 2.1

Also try,

bash$ cat /etc/*-version*


bash$ cat /etc/issue

These files should exist in most distributions. They are created or installed from the installer package when you first install the system. However, if you have previously updated the kernel manually since installing the operating system then the information in these files might be wrong.


lsb_release (Linux Standard Base Release) is another command which prints out useful information about the distribution. The command has several options to print out specific information, but the -a or the –all option prints out all the information.

bash$ lsb_release -a
LSB Version: n/a
Distributor ID: Gentoo
Description: Gentoo Base System release 2.1
Release: 2.1
Codename: n/a


Another option you have is to check the proc version. You can do so by using the cat command to print out the contents of the /proc/version file.

bash$ cat /proc/version
Linux version 3.3.0-gentoo (root@machinename) (gcc version 4.5.3 (Gentoo 4.5.3-r2 p1.1, pie-0.4.7) ) #2 SMP PREEMPT Wed Mar 21 02:07:10 CDT 2012

This prints out a complete and detailed list of information about your kernel, processor, machine and operating system.

I usually rely on either the uname or the /proc/version file to get the reliable version information for the OS as well as the kernel. You can use the other methods if either of these two options does not work.