Numerous Linux distributions exist, such as Ubuntu, Fedora, and openSUSE. Each distribution varies in many aspects, and you may need to identify the name and version of your Linux system, often for programmatic purposes.

The Linux Foundation provides the lsb_release specification and command to display distribution-specific information easily. However, not all Linux distributions include lsb_release by default. Most store this information in the /etc directory, but with slightly different file names. Additionally, the hostnamectl and uname commands can reveal some information about the Linux distribution name and version.

To find details like the Linux distribution name and version, try each of the following methods, as one might work for one distribution but not another.

Steps to check Linux distribution name and version information:

  1. Open the terminal.
  2. Execute the 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. Examine the contents of the /etc/<distribution>-release file.
    $ cat /etc/centos-release
    CentOS Linux release 8.3.2011
  4. Examine the contents of the /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 additional details about your Linux distribution by examining the contents of the /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. Examine the contents of the /etc/lsb-release file.
    $ cat /etc/lsb-release 
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=20.10
    DISTRIB_CODENAME=groovy
    DISTRIB_DESCRIPTION="Ubuntu 20.10"
  7. Retrieve OS and distribution information using the 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. Obtain Linux system information using the 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.