Understanding How to Check Your Linux Operating System Version
Knowing your Linux operating system version is essential for system administration, software compatibility, and troubleshooting. Whether you're a beginner or an experienced user, identifying your Linux distribution and version helps ensure optimal performance and security. This guide explores the most reliable commands to know the OS version in Linux, along with their usage, outputs, and scenarios where they excel.
Real talk — this step gets skipped all the time.
Using cat /etc/os-release
The simplest and most widely supported method to check your Linux OS version is the cat /etc/os-release command. This file contains standardized information about your distribution, including the name, version, and ID Simple as that..
Example:
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 22.04.3 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
When to Use:
- Works on most modern Linux distributions (Ubuntu, Debian, CentOS, Fedora, etc.).
- Ideal for scripting or automation since the output is structured.
Note: Older systems may use /etc/*-release files (e.g., /etc/redhat-release) Practical, not theoretical..
Using lsb_release -a
The lsb_release command is part of the Linux Standard Base (LSB) and provides user-friendly OS information.
Example:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy
When to Use:
- If
/etc/os-releaseis missing or corrupted. - Provides clean, human-readable output.
Installation Note:
On some minimal systems, install the lsb-release package:
sudo apt install lsb-release # For Debian/Ubuntu
sudo dnf install lsb-release # For Fedora/RHEL
Using neofetch or screenfetch
For a visually appealing system summary, tools like neofetch or screenfetch display your OS version alongside hardware details, kernel information, and desktop environment Worth keeping that in mind..
Example with neofetch:
$ neofetch
.-/+oos+//:.
`:+ssssssssssssss+:`
-+ssssssssssssssyyyyssss+-
.ossssssssssssssdddddddddssssso.:
:sssssssssssssdddddddddddddddddss+:`
-sssssssssssssdddddddddddddddddddo+:
:sssssssssssssddddddddddddddddddddd+:
+sssssssssssssddddddddddddddddddddd/
ssssssssssssssssssssssssssssssssssss/
ssssssssssssssssssssssssssssssssssss/
ssssssssssssssssssssssssssssssssssss/
ssssssssssssssssssssssssssssssssssss/
ssssssssssssssssssssssssssssssssssss+
+ssssssssssssssssssssssssssssssssssso
:sssssssssssssssssssssssssssssssssss/
:sssssssssssssssssssssssssssssssssss/
:ssssssssssssssssssssssssssssssssso`
-ssssssssssssssssssssssssssssssso+-
:sssssssssssssssssssssssssssssso`
.osssssssssssssssssssssssssssso/.
-+ssssssssssssssssssssssso+-
`:+sssssssssssssssss+:`
.-/+oos+//:.
OS: Ubuntu 22.Here's the thing — 04. 3 LTS
Kernel: 5.Worth adding: 15. 0-91-generic x86_64
...
**When to Use:**
- For quick visual summaries of system information.
- Not installed by default; install via:
```bash
sudo apt install ne
## Installing and Using `neofetch`
If you prefer a colorful, one‑line summary that also showcases your system’s hardware, `neofetch` is a popular choice.
**Installation**
```bash
sudo apt install neofetch # Debian/Ubuntu
sudo dnf install neofetch # Fedora/RHEL/CentOS
sudo pacman -S neofetch # Arch Linux
Basic usage
$ neofetch
.-/+oos+//:.
`:+ssssssssssssss+:`
-+ssssssssssssssyyyyssss+-
.ossssssssssssssdddddddddssssso.:
:sssssssssssssdddddddddddddddddss+:`
-sssssssssssssdddddddddddddddddddo+:
:sssssssssssssddddddddddddddddddddd+:
+sssssssssssssddddddddddddddddddddd/
... (ASCII art continues) ...
OS: Ubuntu 22.04.And 3 LTS
Kernel: 5. And 15. 0-91-generic x86_64
Uptime: 12 h 23 m
Desktop: GNOME 42
Terminal: xterm‑256color
CPU: AMD Ryzen 7 5800H (12) @ 3.
**When to Use**
- Quick visual overviews for support tickets or system inventories.
- When you need a single command that prints both OS and hardware details.
---
## Using `screenfetch`
Another lightweight, ASCII‑art generator, `screenfetch`, offers a slightly different layout and can be customized with themes.
**Installation**
```bash
sudo apt install screenfetch # Debian/Ubuntu
sudo dnf install screenfetch # Fedora/RHEL
sudo pacman -S screenfetch # Arch Linux
Basic usage
$ screenfetch
_______________________________
| _ |
| | | |
| _ __ ___| |__ ___ _ __ |
| | '_ \ / _ \ '_ \ / _ \ '__|
| | | | | __/ |_) | __/ |
| |_| |_|\___|_.__/ \___|_|
| |
| Ubuntu 22.04.3 LTS |
| Kernel 5.15.0-91-generic |
| Desktop: GNOME 42 |
| CPU: AMD Ryzen 7 5800H |
| Memory: 16GiB |
_______________________________
When to Use
- Ideal when you want a compact, terminal‑friendly snapshot without the extensive artwork of
neofetch. - Works well in scripts that parse the output (e.g., extracting the OS version).
Leveraging Built‑in System Files
For the most reliable, distribution‑agnostic method, you can read the standard OS description files directly.
/etc/os-release (or /usr/lib/os-release)
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
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"
Key fields: PRETTY_NAME, VERSION_ID, VERSION_CODENAME.
When to Use: Always present on modern Debian‑based and Red Hat‑based systems; perfect for scripting because the output is key‑value pairs that can be parsed with grep, awk, or grep -oP.
/etc/lsb-release (deprecated but still present)
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
Another quick way to retrieve distribution information is the **`lsb_release`** utility, which reads the same data found in `/etc/lsb-release` but presents it in a friendly, command‑line format.
### `lsb_release` command
```bash
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy
Useful switches
-dor--description– prints only the descriptive line.-ror--release– shows the version number.-cor--codename– outputs the codename.-aor--all– displays all fields (as above).
When to use
- Ideal for scripts that need a single, parsable line (e.g.,
lsb_release -rsgives22.04). - Present on most Debian‑ and Red Hat‑derived systems; if missing, install the
lsb-releasepackage.
hostnamectl – the systemd way
Modern systems that run systemd expose OS details through hostnamectl That alone is useful..
$ hostnamectl
Static hostname: my-laptop
Icon name: computer-laptop
Chassis: laptop
Machine ID: 3f9a1b2c4d5e6f7g8h9i0j1k2l3m4n5o
Boot ID: a1b2c3d4-5e6f-7g8h-9i0j-klmnopqrstuv
Virtualization: none
Operating System: Ubuntu 22.04.3 LTS
Kernel: Linux 5.15.0-91-generic
Architecture: x86-64
Key fields – Operating System and Kernel.
When to use
- When you already rely on systemd for other management tasks.
- The output is already key‑value friendly; you can grep for
Operating System:orKernel:.
Reading /etc/issue and /etc/issue.net
These files contain the pre‑login banner and often hold a human‑readable OS string Simple, but easy to overlook..
$ cat /etc/issue
Ubuntu 22.04.3 LTS \n \l
The \n and \l are escape sequences replaced by a newline and the tty name at login time.
When to use
- For a ultra‑lightweight check when no extra tools are installed.
- Useful in minimal containers or rescue environments where only
/etc/issueis guaranteed.
Generic /etc/*release files
Many distributions drop a release file in /etc/ (e.g., /etc/redhat-release, /etc/debian_version). A simple glob can capture them:
$ for f in /etc/*release /etc/*_version; do [ -r "$f" ] && echo "$f:" && cat "$f"; done
/etc/os-release:PRETTY_NAME="Ubuntu 22.04.3 LTS"
...
/etc/lsb-release:DISTRIB_ID=Ubuntu
...
/etc/debian_version:12.5
When to use
- When you need a distribution‑agnostic fallback that works on both Debian‑ and Red Hat‑family systems.
- Perfect for provisioning scripts that must adapt to unknown hosts.
uname – kernel‑centric view
While uname does not give the distro name, it supplies the kernel release, which is often paired with /etc/os-release for a complete picture Most people skip this — try not to..
$ uname -r
5.15.0-91-generic
$ uname -m
x86_64
$ uname -s
Linux
When to use
- In environments where only the kernel version matters (e.g., checking driver compatibility).
- Combined with
cat /etc/os-releaseto produce a full “OS + kernel” string.
inxi – a full‑featured hardware & OS reporter
For those who want more detail than neofetch or screenfetch but still prefer a single command, inxi is a powerful option.
```bash
$ inxi -S
System: Host: my-laptop Kernel: 5.15.0-91-generic x86_64 bits: 64 Desktop: GNOME 42.5 Distro: Ubuntu 22.04.3 LTS
When to use
- When you need a concise, parseable summary that includes desktop environment and architecture alongside distro and kernel.
- Ideal for support requests, inventory scripts, or quick system profiling without installing heavier tools.
distrobox-host-exec / Container detection
In containerized or toolbox environments, the host OS may differ from the container's userspace. distrobox-host-exec (available in Distrobox setups) lets you query the host directly:
$ distrobox-host-exec cat /etc/os-release
PRETTY_NAME="Fedora Linux 39 (Workstation Edition)"
...
When to use
- When running inside a container, toolbox, or VM and you need the host distribution details.
- Helpful for CI/CD pipelines that spawn build containers on heterogeneous hosts.
Putting it together: a portable detection snippet
For scripts that must run anywhere—from a minimal Alpine container to a full RHEL workstation—combine the most reliable sources with graceful fallbacks:
detect_os() {
local os="" kernel="" pretty=""
# 1. Preferred: /etc/os-release (systemd standard)
if [ -r /etc/os-release ]; then
. /etc/os-release
os="${ID:-}"
pretty="${PRETTY_NAME:-}"
fi
# 2. Fallback: lsb_release (if installed)
if [ -z "$os" ] && command -v lsb_release >/dev/null 2>&1; then
os=$(lsb_release -si | tr '[:upper:]' '[:lower:]')
pretty=$(lsb_release -sd)
fi
# 3. Fallback: distribution-specific files
if [ -z "$os" ]; then
if [ -r /etc/debian_version ]; then os="debian"; pretty="Debian $(cat /etc/debian_version)"; fi
if [ -r /etc/redhat-release ]; then os="rhel"; pretty=$(cat /etc/redhat-release); fi
if [ -r /etc/alpine-release ]; then os="alpine"; pretty="Alpine Linux $(cat /etc/alpine-release)"; fi
fi
# Kernel (always available)
kernel=$(uname -r)
printf 'OS=%s\nPRETTY="%s"\nKERNEL=%s\n' "$os" "$pretty" "$kernel"
}
This function yields consistent OS=, PRETTY=, and KERNEL= variables regardless of the underlying distribution, making it suitable for provisioning tools, monitoring agents, or cross-platform installers.
Conclusion
Linux exposes its identity through multiple overlapping interfaces—each with distinct strengths. Consider this: /etc/os-release remains the gold standard for programmable access, while hostnamectl excels on systemd-based desktops and servers. lsb_release bridges LSB-compliant distributions, and the classic /etc/*release glob provides a zero-dependency fallback. For kernel-centric tasks, uname is indispensable, and tools like inxi or neofetch deliver human-friendly summaries when diagnostics or support tickets demand richer context.
Choose the method that matches your environment's constraints:
- Scripts & automation →
/etc/os-release+uname - Interactive admin work →
hostnamectlorinxi -S - Minimal / unknown systems → glob
/etc/*releasewithlsb_releasefallback - Container host introspection →
distrobox-host-exec
By layering these approaches, you gain a solid, distribution-agnostic way to answer "What OS am I running?"—whether you're on a Raspberry Pi, a cloud VM, or a developer's laptop.