Knowing what Linux distribution, version, and kernel you are running is fundamental to system administration. Whether you are troubleshooting a package issue, writing automation scripts, or filing a bug report, you need this information at your fingertips. Linux provides several commands and files that reveal distribution details, kernel version, architecture, and init system. This guide covers all the practical methods and explains when to use each one.

Check Distribution Name and Version with /etc/os-release

The /etc/os-release file is the standard way to identify a Linux distribution. It exists on virtually every modern distribution and follows a consistent key-value format defined by the freedesktop.org specification.

cat /etc/os-release

Sample output on Ubuntu 24.04:

PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
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"

On RHEL 10 or Rocky Linux 10, the output looks different but follows the same format:

NAME="Rocky Linux"
VERSION="10.0 (Pelican)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="10.0"
PLATFORM_ID="platform:el10"

The key fields to note are ID (short identifier), VERSION_ID (numeric version), and ID_LIKE (parent distribution family). These are the fields you should use in scripts rather than parsing human-readable strings.

Check with lsb_release

The lsb_release command provides Linux Standard Base information. It is not installed by default on all distributions, but it is available in most package repositories.

lsb_release -a

Sample output:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.1 LTS
Release:        24.04
Codename:       noble

If the command is not found, install it:

# Debian/Ubuntu
sudo apt install -y lsb-release

# RHEL/Rocky/Alma
sudo dnf install -y redhat-lsb-core

For quick checks, lsb_release -d gives you just the description line, and lsb_release -r gives the release number.

Check with hostnamectl

On systems running systemd (which covers the vast majority of modern distributions), hostnamectl provides distribution and kernel information along with hostname details:

hostnamectl

Sample output:

 Static hostname: webserver01
       Icon name: computer-vm
         Chassis: vm
      Machine ID: a1b2c3d4e5f6...
         Boot ID: f6e5d4c3b2a1...
  Virtualization: kvm
Operating System: Ubuntu 24.04.1 LTS
          Kernel: Linux 6.8.0-45-generic
    Architecture: x86-64

This command is particularly useful because it shows the operating system, kernel version, and architecture in a single output. It also tells you if the system is virtualized and what hypervisor is in use.

Check Kernel Version with uname

The uname command is the standard tool for kernel information. It is available on every Linux system and every Unix-like operating system.

To see all available information:

uname -a

Sample output:

Linux webserver01 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC x86_64 x86_64 x86_64 GNU/Linux

Breaking down the flags:

  • uname -s – Kernel name (Linux)
  • uname -r – Kernel release version (6.8.0-45-generic)
  • uname -v – Kernel build version and date
  • uname -m – Machine hardware name (x86_64, aarch64)
  • uname -n – Network hostname
  • uname -o – Operating system (GNU/Linux)

For most purposes, uname -r is the flag you need. It returns just the kernel version string, which is what you reference when checking driver compatibility or kernel module requirements:

uname -r
6.8.0-45-generic

Check /proc/version

The /proc/version virtual file contains kernel version information along with the compiler used to build it:

cat /proc/version

Sample output:

Linux version 6.8.0-45-generic (buildd@lcy02-amd64-080) (x86_64-linux-gnu-gcc-13 (Ubuntu 13.2.0-23ubuntu4) 13.2.0, GNU ld (GNU Binutils for Ubuntu) 2.42) #45-Ubuntu SMP PREEMPT_DYNAMIC

This is useful when you need to know which GCC version compiled the running kernel, which matters when building out-of-tree kernel modules.

Determine the Init System

Most current distributions use systemd, but some lightweight or embedded distributions still use OpenRC, runit, or SysVinit. Knowing the init system tells you how to manage services.

The simplest check is to look at PID 1:

ps -p 1 -o comm=

This returns systemd, init, openrc-init, or whatever process is running as PID 1.

You can also check for the presence of systemd directly:

systemctl --version

If this command succeeds and returns a version number, you are running systemd. If it fails with “command not found,” the system uses a different init system.

For OpenRC (used by Alpine Linux and Gentoo):

rc-status --version

Check System Architecture

Knowing whether you are on x86_64, ARM64, or another architecture is critical when downloading pre-built binaries or compiling software.

The quickest check:

arch

This returns x86_64, aarch64, armv7l, or similar. It is equivalent to uname -m.

On Debian-based systems, you can also check the package architecture:

dpkg --print-architecture

This returns amd64, arm64, armhf, or i386. Note that the naming convention differs from uname -m – dpkg uses Debian’s architecture naming scheme where amd64 corresponds to x86_64.

Check if Running 32-bit or 64-bit

There are several ways to determine whether you are running a 32-bit or 64-bit system.

Using getconf:

getconf LONG_BIT

This returns either 32 or 64. It is the most direct answer to the question.

Using the file command on a system binary:

file /usr/bin/bash

Look for “64-bit” or “32-bit” in the output:

/usr/bin/bash: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked...

You can also check CPU capabilities to see if the hardware supports 64-bit even if the OS is running in 32-bit mode:

lscpu | grep "CPU op-mode"

If the output includes “64-bit,” the CPU supports it regardless of what the OS is running.

Using os-release Variables in Scripts

The /etc/os-release file is designed to be sourced in shell scripts. This lets you write distribution-aware automation without fragile string parsing.

#!/bin/bash

# Source os-release variables
. /etc/os-release

echo "Distribution: $NAME"
echo "Version: $VERSION_ID"
echo "Family: $ID_LIKE"

# Conditional logic based on distribution
case "$ID" in
  ubuntu|debian)
    echo "Using apt package manager"
    PKG_MGR="apt"
    ;;
  rhel|rocky|almalinux|centos|fedora)
    echo "Using dnf package manager"
    PKG_MGR="dnf"
    ;;
  arch)
    echo "Using pacman package manager"
    PKG_MGR="pacman"
    ;;
  opensuse*|sles)
    echo "Using zypper package manager"
    PKG_MGR="zypper"
    ;;
  *)
    echo "Unknown distribution: $ID"
    exit 1
    ;;
esac

# Version-specific logic
if [[ "$ID" == "ubuntu" && "$VERSION_ID" == "24.04" ]]; then
  echo "Running on Ubuntu 24.04 - Noble Numbat"
fi

This approach is far more reliable than parsing the output of lsb_release or reading distribution-specific files like /etc/redhat-release. The variables are standardized across distributions, and the file is guaranteed to exist on any distribution following the freedesktop.org specification.

For more complex version comparisons in scripts:

#!/bin/bash

. /etc/os-release

# Compare version numbers
version_ge() {
  printf '%s\n%s' "$2" "$1" | sort -V -C
}

if version_ge "$VERSION_ID" "24.04"; then
  echo "Running version $VERSION_ID which is 24.04 or newer"
fi

Quick Reference Summary

Here is a quick overview of what each command tells you:

  • cat /etc/os-release – Distribution name, version, codename, family
  • lsb_release -a – Distribution name, version, codename (may need installation)
  • hostnamectl – Distribution, kernel, architecture, virtualization (systemd only)
  • uname -a – Kernel version, architecture, hostname
  • uname -r – Kernel release version only
  • cat /proc/version – Kernel version with compiler information
  • arch – CPU architecture
  • getconf LONG_BIT – 32-bit or 64-bit
  • ps -p 1 -o comm= – Init system

Conclusion

Every Linux administrator should have these commands committed to muscle memory. For interactive use, hostnamectl gives you the most information in a single command. For scripting, source /etc/os-release and use its standardized variables to write portable automation that works across distributions. When troubleshooting kernel-related issues, uname -r is your go-to. Together, these tools give you a complete picture of any Linux system in seconds.

LEAVE A REPLY

Please enter your comment!
Please enter your name here