How To Find Linux Version

How To Find Linux Version

Reading time1 min
#Linux#OpenSource#Sysadmin#LinuxVersion#Kernel#LinuxCommands

Mastering Linux Version Detection: Beyond uname and lsb_release

When managing Linux systems — whether you’re a sysadmin, developer, or enthusiast — knowing the exact distribution and kernel version is vital. This knowledge helps you ensure software compatibility, tailor troubleshooting steps, and apply appropriate security patches. While many tutorials and quick tips stop at the basics like uname -a or lsb_release -a, these commands don’t always tell the full story. In this post, we'll go beyond the basics and explore deeper methods to accurately detect your Linux version.


Why Go Beyond uname and lsb_release?

  • uname -a shows kernel information but not distribution details.
  • lsb_release -a gives distribution info but relies on packages that might not be installed everywhere (e.g., minimal containers).
  • Some systems don’t have either command available.
  • System files and other utilities provide richer detail—such as patch-levels, flavor, or codename.

The Basics Recap

Before diving deeper, let's quickly recap what the common commands deliver:

$ uname -a
Linux myhost 5.15.0-70-generic #77-Ubuntu SMP Fri Mar 24 14:05:43 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

This tells us the kernel version, hostname, architecture, and build metadata.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:        22.04
Codename:       jammy

This reveals distributor specifics but needs the LSB utilities installed.


Beyond the Basics: Alternative Files and Commands

1. Checking /etc/os-release

Most modern Linux distributions include this file which contains detailed info about the operating system:

$ cat /etc/os-release

NAME="Ubuntu"
VERSION="22.04.2 LTS (Jammy Jellyfish)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 22.04.2 LTS"
VERSION_ID="22.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=jammy
UBUNTU_CODENAME=jammy

Why /etc/os-release?
It’s standardized (supported by systemd-based distros) and present in Fedora, Ubuntu, Debian, Arch, CentOS, and others.

You can grab specific values with shell tools:

source /etc/os-release
echo "You are running $PRETTY_NAME ($VERSION_ID)"

2. Inspecting Distribution-specific Release Files

Various distros maintain their own identification files inside /etc/. Here are common examples:

$ cat /etc/debian_version       # Debian-based OSes like Ubuntu, Mint
10.9

$ cat /etc/redhat-release       # Red Hat-based distros (RHEL/CentOS/Fedora)
CentOS Linux release 7.9.2009 (Core)

$ cat /etc/issue               # A simple text banner shown before login prompt; often contains distro info.
Ubuntu 22.04 LTS \n \l 

You can quickly check for these files to get clues about the distro if os-release is unavailable:

for f in /etc/*release /etc/*version; do 
    [ -f "$f" ] && echo "$f:" && head -1 "$f" && echo; 
done

3. Using hostnamectl

On systems with systemd (which is nearly all current mainstream distributions), hostnamectl also outputs OS details:

$ hostnamectl

   Static hostname: myhost.example.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: ae17c898e1ae423291cc6c8384385442
           Boot ID: e69bc75837f2474c8e541deb55ea1498
    Virtualization: kvm
  Operating System: Ubuntu 22.04.2 LTS
            Kernel: Linux 5.15.0-70-generic
      Architecture: x86-64       

4. Leveraging Package Managers for Version Info

If you want to know which version of certain core packages or kernel headers are installed (helps with debugging compilation or module issues):

  • On Debian/Ubuntu:
dpkg-query -W | grep linux-image

ii  linux-image-5.15.0-70-generic          5.15.0-70            amd64        Signed kernel image generic  
  • On RedHat/Fedora:
rpm -qa | grep kernel-core

kernel-core-5.14.12-300.fc35.x86_64  

5. Kernel Version Breakdown with /proc/version

Inspect this file for additional context:

$ cat /proc/version

Linux version 5.15.0-70-generic (buildd@lcy02-amd64-035) (gcc (Ubuntu 11.3) 11....

This gives compiler version used to build the kernel along with kernel version string.


Bonus: Script to Detect Linux Version More Reliably

Here’s a lightweight Bash script snippet that tries multiple methods—great for automation or troubleshooting scripts.

#!/bin/bash

echo "Kernel info via uname:"
uname -srmp

if [ -f /etc/os-release ]; then
    . /etc/os-release
    echo "Distro info from /etc/os-release:"
    echo "Name: $NAME"
    echo "Version: $VERSION"
else 
    # Fallback to other release files:
    if [ -f /etc/lsb-release ]; then 
        . /etc/lsb-release 
        echo "Distro info from /etc/lsb-release:"
        echo "Distributor ID: $DISTRIB_ID" 
        echo "Description : $DISTRIB_DESCRIPTION" 
    else 
        echo "Other release files present:"
        grep '^NAME=' /etc/*release || echo "No distro info found."
    fi 
fi 

echo ""
echo "Hostnamectl output summary:"
hostnamectl status | grep 'Operating System\|Kernel'

Save it as detect-linux-version.sh, make executable (chmod +x detect-linux-version.sh) and run it on different machines to get consistent output.


Summary Checklist for Linux Version Detection

MethodInfo ProvidedAvailabilityNotes
uname -aKernel version & buildUniversalNo distro info
lsb_release -aDistribution detailsCommon but may need package install (lsb-release)Not always installed
/etc/os-releaseComprehensive distro metadataModern distrosBest first stop
/etc/*release, /etc/*version filesDistro-specific infoVaries by distroHandles legacy/non-systemd systems
hostnamectlOS & Kernel versionsystemd-basedGreat combined view
Package manager queriesInstalled package versionsDistro-specificUseful for kernel headers & specific components
/proc/versionKernel build metaUniversalAdds compiler & build context

Closing Thoughts

Mastering Linux version detection means knowing where to dig beyond quick commands so you don’t miss critical details during troubleshooting or deployment planning.

Next time you’re asked “Which system/version am I on?”, resist stopping at just:

uname -a && lsb_release -a  

Instead incorporate readings from /etc/os-release, fallback files, and use systemd hints (hostnamectl) to get a full picture — precise and reliable across diverse environments.

Happy diagnosing! 🐧🚀


If you found this guide useful or want a script tailored for your team’s environment, drop a comment below or connect on Twitter at [@YourHandle].