A terminal running `uname -a` and `lsb_release -a`

How to Check Your Linux Version: os-release, uname and lsb_release

Ever wonder what Linux version is running on your machine? I commonly connect to friends’ machines, or to one of my servers, and I have no clue what’s on it. This can make a huge difference, as some distributions use apt, some use dnf or yum, and some use something else entirely. Luckily, there are a few commands that answer this in a second.

In this article, we’re going to cover /etc/os-release, uname, lsb_release, and hostnamectl.

TL;DR

  • Run cat /etc/os-release for distribution information (works on basically every modern distro).
  • Run uname -r for the kernel version, or uname -a for all kernel information.
  • Run lsb_release -a for distribution information, if it’s installed.
  • Run hostnamectl on systemd machines to get the distro, kernel, and hardware all at once.

The thing that trips people up is that the distribution (Ubuntu 24.04, Debian 13, Fedora, Arch…) and the kernel (Linux 6.12, 7.1…) are two different things with two different version numbers. uname only knows about the kernel. Everything else on this list is how you find the distribution.

/etc/os-release: the one that works everywhere

If you only remember one thing from this article, make it this. Pretty much every modern distribution ships a file at /etc/os-release that describes itself, and since it’s just a text file, it works even on minimal installs and Docker containers that don’t have any of the other tools installed. Here’s my desktop:

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.5 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.5 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"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

And here’s one of my servers, which runs Debian:

$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 13 (trixie)"
NAME="Debian GNU/Linux"
VERSION_ID="13"
VERSION="13 (trixie)"
VERSION_CODENAME=trixie
...

The ID_LIKE line is a nice bonus. It tells you which family the distro belongs to, so ID_LIKE=debian means you can expect apt, and something like ID_LIKE="rhel centos fedora" means dnf/yum.

Since the file is written as shell variables, you can also pull single values out of it in a script:

$ . /etc/os-release; echo "$ID $VERSION_ID"
ubuntu 24.04

On Debian, there’s also /etc/debian_version, which has the full point release (13.7 on my server) when you need more detail than VERSION_ID gives you.

uname: kernel information

The uname command is used to print system information about the running kernel, including the kernel name, release, version, and hardware platform. You can use various command line arguments to specify which information you want to see. (If you’re wanting distribution information, uname can’t tell you that, so jump back up to /etc/os-release or down to lsb_release.)

List of useful command line arguments and examples:

  • -a or --all: Prints all information (essentially uses all other flags)
    $ uname -a
    Linux deathcamel57 7.1.5-070105-generic #202607241434 SMP PREEMPT_DYNAMIC Fri Jul 24 14:57:06 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
  • -s or --kernel-name: Prints the kernel name
    $ uname -s
    Linux
  • -n or --nodename: Prints the network node hostname
    $ uname -n
    deathcamel57
  • -r or --kernel-release: Prints the kernel release. This is the one most people mean by “kernel version.”
    $ uname -r
    7.1.5-070105-generic
  • -v or --kernel-version: Despite the name, this prints the kernel’s build information (build number, options, and build date), not the version number
    $ uname -v
    #202607241434 SMP PREEMPT_DYNAMIC Fri Jul 24 14:57:06 UTC 2026
  • -m or --machine: Prints the machine hardware name (the CPU architecture)
    $ uname -m
    x86_64
  • -p or --processor and -i or --hardware-platform: Print the processor type and hardware platform. These aren’t portable: on my Ubuntu desktop they print x86_64, but on my Debian server both just print unknown, so use -m instead
    $ uname -p
    unknown
  • -o or --operating-system: Prints the operating system
    $ uname -o
    GNU/Linux

If you’re wondering why my desktop’s kernel is newer than what Ubuntu 24.04 ships with, it’s because I run mainline kernels. That’s also a good example of why you can’t figure out the distro version from the kernel version: they move independently. If you want to do the same, I wrote about building a Linux kernel from source.

One more kernel trick: cat /proc/version prints the kernel version along with the compiler that built it, and works even where uname is missing (some very minimal containers).

$ cat /proc/version
Linux version 7.1.5-070105-generic (kernel@balboa) (x86_64-linux-gnu-gcc-15 (Ubuntu 15.2.0-12ubuntu1) 15.2.0, GNU ld (GNU Binutils for Ubuntu) 2.46) #202607241434 SMP PREEMPT_DYNAMIC Fri Jul 24 14:57:06 UTC 2026

lsb_release: distribution information

The lsb_release command is used to print distribution-specific information, such as the distributor ID, release, and codename. You can use various command line arguments to specify which information you want to see. For example, lsb_release -i will print the distributor ID, lsb_release -r will print the release, and lsb_release -c will print the codename.

List of useful command line arguments and examples:

  • -a or --all: Prints all information (essentially uses all other flags)
    $ lsb_release -a
    Distributor ID:	Ubuntu
    Description:	Ubuntu 24.04.5 LTS
    Release:	24.04
    Codename:	noble
  • -i or --id: Prints the distributor’s ID
    $ lsb_release -i
    Distributor ID:	Ubuntu
  • -d or --description: Prints the description of the distribution currently running
    $ lsb_release -d
    Description:	Ubuntu 24.04.5 LTS
  • -r or --release: Prints the release of the distribution
    $ lsb_release -r
    Release:	24.04
  • -c or --codename: Prints the codename of the distribution
    $ lsb_release -c
    Codename:	noble
  • -s or --short: Prints the short output format for any information displayed (omits the leading headers). You can combine it with the other flags.
    $ lsb_release -cs
    noble

That last one, lsb_release -cs, is probably where you’ve seen this command before. A lot of install instructions that add an apt repository use it to fill in your release’s codename automatically, with something like:

echo "deb [signed-by=/etc/apt/keyrings/example.gpg] https://repo.example.com/ubuntu $(lsb_release -cs) stable"

On my machine, $(lsb_release -cs) turns into noble, so the repository line points at the packages built for Ubuntu 24.04.

“lsb_release: command not found”

lsb_release isn’t always installed. It’s common on Ubuntu desktops, but minimal installs, containers, and many non-Debian distros don’t have it. You can either install it (sudo apt install lsb-release on Debian/Ubuntu, or sudo dnf install lsb_release on Fedora) or just read /etc/os-release, which has the same information. In scripts, I’d always reach for /etc/os-release, since it’s guaranteed to be there in places lsb_release isn’t.

hostnamectl: everything at once

On any distro that uses systemd (which is most of them now), hostnamectl gives you the distro, kernel, architecture, and even the motherboard in one go. I’ve trimmed out a few lines here:

$ hostnamectl
 Static hostname: deathcamel57
       Icon name: computer-desktop
         Chassis: desktop
Operating System: Ubuntu 24.04.5 LTS
          Kernel: Linux 7.1.5-070105-generic
    Architecture: x86-64
 Hardware Vendor: Gigabyte Technology Co., Ltd.
  Hardware Model: Z690 AORUS ULTRA

This is my go-to when I SSH into a box I’ve never seen, since one command tells me what it is, what it runs, and whether it’s a physical machine or a VM.

Which one should you use?

  • Which distro and version am I on? cat /etc/os-release. It works everywhere. lsb_release -a also works, if it’s installed.
  • Which kernel am I running? uname -r.
  • Is this 64-bit, or ARM? uname -m (x86_64, aarch64, and so on).
  • Give me the whole picture. hostnamectl.
  • Writing a script? Source /etc/os-release and use $ID and $VERSION_ID.

Leave a Reply