There are many available Linux distributions, with some of the popular ones being Ubuntu, Fedora, and openSUSE. Each of the distributions is different in many ways, and in many cases, you will need to know the name and version of the Linux system you are using, often programmatically.

Linux Foundation releases the lsb_release specification and command to display distribution-specific information easily. Unfortunately, not all Linux distributions come with lsb_release installed by default. Most store this information in the /etc directory, but with slightly different filenames. There's also hostnamectl and uname commands that displays some information about the Linux distribution name and version.

To get these pieces of information, such as checking the Linux distribution name and version, you will need to try each of the following methods, as one would work on one Linux distribution but not on the other.

Steps to check Linux distribution name and version information:

  1. Launch terminal.
  2. Run lsb_release command.
    $ lsb_release -a
    LSB Version:  core-11.1.0ubuntu4-noarch:security-11.1.0ubuntu4-noarch
    Distributor ID: Ubuntu
    Description:  Ubuntu 22.04.1 LTS
    Release:  22.04
    Codename: jammy

    Install lsb_core package if you get the No LSB modules are available warning.

    $ sudo apt install lsb-core
  3. View content of /etc/<distribution>-release file.
    $ cat /etc/centos-release
    CentOS Linux release 8.3.2011
  4. View content of /etc/system-release file.
    $ cat /etc/system-release
    CentOS Linux release 8.3.2011

    The file is normally just a symbolic link to /etc/<distribution>-release file.

    $ ls -l /etc/system-release
    lrwxrwxrwx. 1 root root 14 Nov 10 10:49 /etc/system-release -> centos-release
  5. View more details about your Linux distribution by viewing the content of /etc/os-release file.
    $ cat /etc/os-release 
    NAME="CentOS Stream"
    VERSION="9"
    ID="centos"
    ID_LIKE="rhel fedora"
    VERSION_ID="9"
    PLATFORM_ID="platform:el9"
    PRETTY_NAME="CentOS Stream 9"
    ANSI_COLOR="0;31"
    LOGO="fedora-logo-icon"
    CPE_NAME="cpe:/o:centos:centos:9"
    HOME_URL="https://centos.org/"
    BUG_REPORT_URL="https://bugzilla.redhat.com/"
    REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux 9"
    REDHAT_SUPPORT_PRODUCT_VERSION="CentOS Stream"
  6. View content of /etc/lsb-release file.
    $ cat /etc/lsb-release 
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=20.10
    DISTRIB_CODENAME=groovy
    DISTRIB_DESCRIPTION="Ubuntu 20.10"
  7. View OS and distribution information using hostnamectl command.
    $ hostnamectl 
     Static hostname: host
           Icon name: computer-vm
             Chassis: vm
          Machine ID: 421dd0de69664dc49728efbdd7ef476d
             Boot ID: a881d479f0364cb387a972597dce5ee4
      Virtualization: parallels
    Operating System: CentOS Stream 9                 
         CPE OS Name: cpe:/o:centos:centos:9
              Kernel: Linux 5.14.0-165.el9.aarch64
        Architecture: arm64
     Hardware Vendor: Parallels International GmbH.
      Hardware Model: Parallels ARM Virtual Machine
  8. View Linux system information using uname command.
    $ uname -a
    Linux host 5.8.0-34-generic #37-Ubuntu SMP Thu Dec 10 18:01:14 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

    Some information can be inferred such as kernel version 5.8 for this system is what Ubuntu 20.10 ships with.

Discuss the article:

Comment anonymously. Login not required.