Command To Find Linux Version

Command To Find Linux Version

Reading time1 min
#Linux#CommandLine#OpenSource#LinuxVersion#SysAdmin#LinuxCommands

Mastering the Command Line: How to Accurately Identify Your Linux Version

Forget generic commands that give vague info—discover the precise methods and tools to pinpoint your Linux distribution and version with absolute confidence, empowering better system management.


If you’ve ever tried troubleshooting a Linux system or installing software, you know that knowing your exact Linux version isn’t just a nice-to-have—it’s essential. Different distributions and versions may use varying package managers, system libraries, or configurations. Without pinpointing the exact Linux version, you might apply incompatible updates or follow wrong guides, leading to headaches or even system instability.

In this post, I’ll show you how to master the command line to find your Linux distribution and version accurately. No more guessing or relying on vague outputs—just clear, reliable commands that give you the info you need quickly.


Why Knowing Your Exact Linux Version Matters

  • Compatibility: Software often supports only certain Linux versions. Installing the wrong version can cause incompatibilities.
  • Troubleshooting: Precise version info helps in searching for relevant bug fixes, forums, or documentation.
  • Security: Security patches vary between versions—you need to know your exact version to apply appropriate updates.
  • Automation & Scripting: Scripts often branch logic based on distro/version to avoid errors.

Guaranteed Ways to Find Your Linux Version Using the Command Line

Linux doesn’t have a single universal command for version info, but distributions follow some conventions. Here are the most reliable methods:


1. Check /etc/os-release (The Modern Standard)

Most modern distributions include the /etc/os-release file, a standardized file with detailed OS info.

cat /etc/os-release

Sample output:

NAME="Ubuntu"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 22.04.1 LTS"
VERSION_ID="22.04"
...

Why it’s useful:
You get human-friendly distro name, version, ID, and more. This file is your best first stop.


2. Use lsb_release Command (If Installed)

The lsb_release utility fetches Linux Standard Base info—also reliable and concise.

lsb_release -a

Example output:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy

If you get command not found, install it with:

sudo apt install lsb-release        # Debian/Ubuntu
sudo yum install redhat-lsb-core    # CentOS/RHEL

3. Display Kernel Version with uname (But This Is NOT Your Distro Version!)

uname -r

Output example:

5.15.0-52-generic

This shows the Linux kernel version, not your distribution version. Useful info but not sufficient alone if you want to know your OS version.


4. Check Distribution-Specific Files

If /etc/os-release isn’t present (older systems), check these files:

  • For Debian/Ubuntu:
cat /etc/lsb-release
cat /etc/debian_version
  • For RedHat/CentOS/Fedora:
cat /etc/redhat-release
cat /etc/centos-release

5. Combining It All in a Script

Here’s a handy bash snippet you can use to quickly gather info:

#!/bin/bash

if [ -f /etc/os-release ]; then
    cat /etc/os-release
elif command -v lsb_release &> /dev/null; then
    lsb_release -a
elif [ -f /etc/lsb-release ]; then
    cat /etc/lsb-release
elif [ -f /etc/debian_version ]; then
    echo "Debian Version:"
    cat /etc/debian_version
elif [ -f /etc/redhat-release ]; then
    cat /etc/redhat-release
else
    echo "Linux version info not found in standard locations."
fi

Save it as check_linux_version.sh, make executable with chmod +x check_linux_version.sh, and run:

./check_linux_version.sh

Summary

  • Always start with cat /etc/os-release for the most detailed, standardized info.
  • Use lsb_release -a if it’s available as a concise alternative.
  • Remember uname -r shows kernel, not distro, version.
  • For older systems, check distro-specific release files.

Knowing your Linux version precisely will save you time, avoid pitfalls, and lead to smarter system management.


Did you find this helpful? Drop a comment below about your favorite command to check Linux versions or share any quirks you’ve encountered!