How to check os version in Linux command line

July 14, 2021 . 2 MIN READ

 

https://www.cyberciti.biz/faq/how-to-check-os-version-in-linux-command-line/

 

cat /etc/os-release

Check os version in Linux

The procedure to find os name and version on Linux:

  1. Open the terminal application (bash shell)
  2. For remote server login using the ssh: ssh user@server-name
  3. Type any one of the following command to find os name and version in Linux:
    cat /etc/os-release
    lsb_release -a
    hostnamectl
  4. Type the following command to find Linux kernel version:
    uname -r

Let us see all examples in details for common Linux distros.

The /etc/os-release file

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

NAME=”Ubuntu”VERSION=”20.04.1 LTS (Focal Fossa)”ID=ubuntuID_LIKE=debianPRETTY_NAME=”Ubuntu 20.04.1 LTS”VERSION_ID=”20.04″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=focalUBUNTU_CODENAME=focal

We can filter out information such as OS version and name using the grep command/egrep command as follows:
$ grep ‘^VERSION’ /etc/os-release
$ egrep ‘^(VERSION|NAME)=’ /etc/os-release
Here is what we see:

NAME=”CentOS Linux”VERSION=”8 (Core)”

Even tiny Linux distro such as Alpine Linux provide the required OS (Operating system) information, including version:

NAME=”Alpine Linux”ID=alpineVERSION_ID=3.12.1PRETTY_NAME=”Alpine Linux v3.12″HOME_URL=”https://alpinelinux.org/”BUG_REPORT_URL=”https://bugs.alpinelinux.org/”

Checking OS version on Linux using the lsb_release command

The lsb_release command gives LSB (Linux Standard Base) and distribution-specific information on the CLI. The syntax is:
$ lsb_release -a
Sample outputs:

LSB Version:  :core-4.1-amd64:core-4.1-noarchDistributor ID:     CentOSDescription:  CentOS Linux release 7.4.1708 (Core) Release:      7.4.1708Codename:     Core

hostnamectl command

Use hostnamectl command to query and change the system hostname and related settings. Just type the following command to check OS name and Linux kernel version:
$ hostnamectl
And it will give info as follows. Look out for “Operating System” and “Kernel“:

Static hostname: nixcraft-www-42         Icon name: computer-vm           Chassis: vm        Machine ID: beb217fbb4324b7d9959f78c279e6599           Boot ID: 10f00cc5ca614b518a84d1793d0134bc    Virtualization: qemu  Operating System: Ubuntu 16.04.3 LTS            Kernel: Linux 4.10.0-42-generic      Architecture: x86-64

Another outputs from my OpenSUSE Linux 15.2 server:

Static hostname: opensuse-nixcraft         Icon name: computer-vm           Chassis: vm        Machine ID: b95459dbd45d428fa513ab6a9636d1a8           Boot ID: 9a144556789241e29b62b962cfb6ba1d    Virtualization: kvm  Operating System: openSUSE Leap 15.2       CPE OS Name: cpe:/o:opensuse:leap:15.2            Kernel: Linux 5.3.18-lp152.50-default      Architecture: x86-64

uname command

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

 

Leave a Reply

Your email address will not be published. Required fields are marked *