To check the Linux OS name and version from the command line, the most portable command is cat /etc/os-release — it’s a plain file present on every modern Linux. lsb_release -a and hostnamectl work too when they’re installed. For the kernel version, uname -r does the job.
Last verified: 2026-05-17 on AlmaLinux 9, Ubuntu 22.04, Debian 12, Fedora 40. Originally published 2022-08-18, rewritten and updated 2026-05-17.
TL;DR
# OS name + version (most portable — works on every modern Linux)
cat /etc/os-release
# Cleaner formatted output (if the lsb-release package is installed)
lsb_release -a
# System summary (OS + kernel + arch)
hostnamectl
# Kernel version only
uname -r
# Everything from uname (kernel + hostname + arch + build date)
uname -a
/etc/os-release — the universal way
cat /etc/os-release
Sample output on Ubuntu 22.04:
PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
The ID and VERSION_ID fields are stable, lowercase, scriptable. For shell scripts that need to branch on distro:
source /etc/os-release
case "$ID" in
ubuntu|debian) echo "Debian-family";;
almalinux|rocky|rhel|centos|fedora) echo "RHEL-family";;
*) echo "Other: $ID";;
esac

lsb_release -a — clean output, requires package
lsb_release -a
Output:
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
If it errors with command not found, install the package (sudo apt install lsb-release on Debian/Ubuntu, sudo dnf install redhat-lsb-core on older RHEL). Newer RHEL/AlmaLinux/Rocky have moved away from lsb-release — use /etc/os-release there.
Kernel version with uname
# Just the kernel release
uname -r # e.g. 5.15.0-105-generic
# Everything
uname -a # kernel + hostname + arch + build date
Frequently asked questions
/etc/os-release and lsb_release? /etc/os-release is a plain file present on every modern Linux (systemd-based) — guaranteed to exist, no command needed. lsb_release is a command from the lsb-release package (sometimes not installed by default on minimal images). For a script that has to run anywhere, cat /etc/os-release is the safer choice.
uname -r for the release string (e.g. 5.15.0-105-generic), uname -a for everything (kernel, hostname, arch, build date). Note the kernel version is independent of the distro version — Ubuntu 22.04 has shipped multiple kernels over its life, all reported by uname -r.
hostnamectl show ‘Operating System’ on one line and ‘Kernel’ on another? hostnamectl consolidates information from /etc/os-release (Operating System line) and uname (Kernel line) into one tidy block. It’s a quick way to see both at once without running two commands.
cat /etc/os-release works on every systemd-based system, including Alpine and most slim container images. For non-systemd / pre-systemd systems (rare now), fall back to cat /etc/issue or cat /etc/*release* — one of them will have what you need.
Related guides
- How to Check Your Ubuntu Version
- How to List Network Devices on Linux
- How to Add and Delete Users on a Linux Server from the Terminal
References
man os-release, man uname, man hostnamectl on any Linux. systemd os-release spec: freedesktop.org/software/systemd/man/latest/os-release.html.