Check OS version in Linux Command line/Terminal

Linux is a free and open source operating system. There are many variants of Linux out there. They are typically called Linux distribution. Suse, OpenSUSE, Debian, Ubuntu, CentOS, Arch, Fedora, RHEL all are common Linux distribution names. Knowing your os version and name can be very useful for security patches.

Check os version in Linux

To find os name and version on Linux variant:

  1. Open the terminal or bash shell usually from root login
  2. Using the ssh: ssh user@server-name
  3. Type the command to find the OS name and version in Linux variant:
    cat /etc/os-release
    lsb_release -a
    hostnamectl
  4. Type the command to find the Linux kernel version:
    uname -r

Let us see all examples in detailed.

/etc/os-release file

Type the following:
$ cat /etc/os-release
Sample outputs:

NAME="Ubuntu"
	VERSION="xx.xx"
	ID=ubuntu
	ID_LIKE=debian
	PRETTY_NAME="Ubuntu xx.xx"
	VERSION_ID="17.10"
	HOME_URL="https://www.ubuntu.com/"
	SUPPORT_URL="https://help.ubuntu.com/"
	BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
	PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
	VERSION_CODENAME=artful
	UBUNTU_CODENAME=artful

lsb_release command

The lsb_release command gives LSB information on the CLI. The syntax will be:
$ lsb_release -a
Sample outputs:

LSB Version:	:core-4.1-amd64:core-4.1-noarch
	Distributor ID:	CentOS
	Description:	CentOS Linux release X.x.xxxx (Core) 
	Release:	7.4.1
	Codename:	Core

hostnamectl command

Use hostnamectl command to query and change the system hostname. Just type the command to check the OS name and Linux kernel version:
$ hostnamectl
Sample outputs:

   Static hostname: minitick.in
	Icon name: computer-vm
	Chassis: vm
	Machine ID: XXXXXXXXXXXXXXXXXXXXXXXX
	Boot ID: XXXXXXXXXXXXXXXXXXXXXXXXXX
	Virtualization: qemu
	Operating System: Ubuntu x.xxx.xxx
	Kernel: Linux 4.10.0-42-generic
	Architecture: x86-64

uname command

Just print Linux kernel version, run:
$ uname -r
Sample outputs:

Another option is to type the command:
$ cat /proc/version
Sample outputs:

Linux version x.xx.xxxxx.xx.x86_64 ([email protected]) (gcc version x.x.x X.XXXXXX (Red Hat 4.8.5-16) (GCC) ) 

/etc/issue file

Use more command/less command as follows:
$ cat /etc/issue
$ more /etc/issue
$ less /etc/issue

Getting help

You can also view the manual page on uname using the command:
$ man hostnamectl
$ man uname
$ man cat

linux,terminal,os,command line