lsb_release
Show Linux Standard Base and distribution information
By CMD Script Team · 3 min read · Last updated
lsb_release [OPTIONS]Options
| Flag | Description |
|---|---|
-a | Print all fields: distributor ID, description, release, and codename |
-d | Print the distribution's descriptive name only |
-r | Print only the release/version number |
-c | Print only the release codename, e.g. jammy or bookworm |
-i | Print only the distributor ID, e.g. Ubuntu or Debian |
-s | Print output in short format, without field labels (useful for scripting) |
Distribution compatibility
- Ubuntu
- Debian
- Fedora (may need lsb_release install)
- Arch (not installed by default)
- macOS (not available; no LSB concept)
What it does
lsb_release prints Linux Standard Base and distribution-specific information, including
the distributor name (e.g. Ubuntu, Debian), the release version number, and the release
codename (e.g. jammy, bookworm). It's the quickest way to answer "which distro and
version am I actually running?" — something uname deliberately does not tell you,
since uname only reports kernel details.
Beginner examples
lsb_release -a— print distributor ID, description, release, and codenamelsb_release -d— print just the friendly description, e.g.Ubuntu 24.04.1 LTSlsb_release -r— print just the release number, e.g.24.04lsb_release -c— print just the codename, e.g.noble
lsb_release -a
Advanced examples
- Get script-friendly output without field labels:
lsb_release -s - Combine flags for a compact one-liner:
lsb_release -sir→Ubuntu 24.04 - Use the codename to add the right APT repository line:
lsb_release -sc - Fall back gracefully in scripts when the command is missing:
command -v lsb_release >/dev/null && lsb_release -d || cat /etc/os-release - Check distributor ID before branching install logic in a provisioning script:
[ "$(lsb_release -si)" = "Ubuntu" ] && apt install ...
lsb_release -sir
Common mistakes
- Assuming
lsb_releaseis preinstalled everywhere — it's frequently missing on minimal images, containers, and Arch-based systems, causing "command not found" errors in scripts that assume it exists. - Parsing
lsb_release -a's labeled output with fragile string splitting instead of using-sfor clean, label-free values meant for scripting. - Confusing "release" (the version number) with "codename" — automation that adds
APT repositories usually needs the codename (
-c), not the release number (-r). - Forgetting that on Debian,
lsb_release -acan be slow the first time it runs because it queriesdpkg— subsequent runs are cached and fast.
Tips
- Use
lsb_release -scwhen generating APT source list entries that reference the distro codename (e.g.deb ... jammy main). - If
lsb_releaseisn't installed,apt install lsb-release(Debian/Ubuntu) ordnf install redhat-lsb-core(Fedora/RHEL-family) adds it. - For maximum portability across distros, prefer
/etc/os-releasein shell scripts; reservelsb_releasefor interactive/human use.
Best practices
- In provisioning or CI scripts, don't hard-depend on
lsb_releasebeing present — detect it withcommand -v lsb_releaseand fall back to/etc/os-release. - Use the
-sflag family (-si,-sr,-sc,-sd) for any output you intend to parse programmatically, since it strips the human-readable labels. - Document which exact field (
ID,release, orcodename) your automation depends on — they're easy to conflate and cause subtle bugs in repository configuration.
Try it yourself
A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.
Real-world use cases
- Quickly confirming which Ubuntu/Debian release a server is running before applying an OS-specific fix or patch.
- Generating the correct APT repository line for third-party software that ships per-codename packages (e.g. Docker's official install script).
- Including distro name/version in bug reports or support tickets alongside
uname -a. - Branching provisioning scripts (Ansible, shell) based on distributor ID or codename.
Common interview questions
- How is
lsb_releasedifferent fromuname?unamereports kernel-level facts (kernel name, release, architecture);lsb_releasereports distribution-level facts (distributor name, distro version, codename) — the two answer different questions. - What would you do if
lsb_releaseisn't installed on a server? Read/etc/os-releaseinstead, which is present on essentially all modern distros without extra packages. - Why might a script prefer
lsb_release -scover-r? Because many third-party APT repositories are keyed by codename (e.g.bookworm,jammy), not by the numeric release version.
Frequently Asked Questions
Why doesn't lsb_release work right after installing my distro?
On many minimal installs (Debian netinst, Fedora minimal, Arch, containers), the lsb-release package isn't installed by default. Install it with your package manager, e.g. apt install lsb-release.
What's a reliable alternative if lsb_release isn't available?
cat /etc/os-release works on virtually every modern Linux distribution without extra packages and gives NAME, VERSION, ID, and VERSION_CODENAME fields.
What does 'LSB' actually stand for?
Linux Standard Base — a now largely deprecated specification meant to standardize the internal structure of Linux distributions so software would behave consistently across them.
Cheat sheet
Download a quick-reference cheat sheet for lsb_release.