Home / Alt manpages / lsb_release(1)

  • lsb_release(1)
  • User command
  • linux

Identify a Linux Distribution with lsb_release

lsb_release --short on its own prints nothing on Debian and Ubuntu's minimal implementation, tripping up anyone who expects the full LSB tool. This guide gets you a reliable distributor ID, release number, codename and description, plus a safe pattern for using those values in shell scripts. The examples use the minimal POSIX-shell implementation from Debian's lsb-release package, version 12.0-2, installed on this machine.

Allow about ten minutes. You need a normal shell and the lsb-release package. Every command here is read-only and should normally run without sudo: the command reads operating-system identification files, it does not upgrade the system, change repositories or alter boot settings.

1. Confirm the installed implementation

Check which executable your shell will run and which package supplied it:

$ command -v lsb_release
/usr/bin/lsb_release
$ dpkg-query -W -f='${Package} ${Version}\n' lsb-release
lsb-release 12.0-2
  • Package versions differ between distributions and releases, so keep this check in a troubleshooting note or deployment report when the exact output matters.
  • This is a bare-bones implementation. The local manual describes it as obtaining its data from /etc/os-release or /usr/lib/os-release while keeping the familiar lsb_release interface.

Checkpoint

If command -v prints nothing, install or restore the package through your normal package-management process. Do not copy a script from another host just to make the command name exist.

2. Print the complete distribution record

Use --all when you need the whole record:

$ lsb_release --all
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.5 LTS
Release:        24.04
Codename:       noble

The values come from the host, so your distributor, version and codename will differ. The four fields have distinct jobs:

  • Distributor ID is a normalised distributor name.
  • Description is intended for people, not scripts.
  • Release is the numeric release identifier.
  • Codename is the distribution's named release.

Do not use the description as a package-manager selector if a project provides a documented repository variable or codename setting instead.

For a one-line diagnostic bundle, save the output rather than trying to parse punctuation from the description:

$ lsb_release --all > /tmp/lsb-release-report.txt
$ test -s /tmp/lsb-release-report.txt && sed -n '1,4p' /tmp/lsb-release-report.txt

Warning

This creates a temporary report and does not change system configuration, but remove it when it is no longer useful, especially if you add other host details to the same file. That deletion is irreversible, so check the path before using rm.

3. Ask for one field at a time

Use the long options when the command is being read by a person or reviewed in a script:

$ lsb_release --id
Distributor ID: Ubuntu
$ lsb_release --description
Description:    Ubuntu 24.04.5 LTS
$ lsb_release --release
Release:        24.04
$ lsb_release --codename
Codename:       noble

The corresponding short options are -i, -d, -r and -c. They can be combined, but option order is not a request to reorder the output: lsb_release -rc still prints the release followed by the codename.

Use --help when you need a quick reminder of the interface:

$ lsb_release --help
Usage: lsb_release [options]

Options:
  -h, --help         show this help message and exit
  -v, --version      show LSB modules this system supports
  -i, --id           show distributor ID
  -d, --description  show description of this distribution
  -r, --release      show release number of this distribution
  -c, --codename     show code name of this distribution
  -a, --all          show all of the above information
  -s, --short        show requested information in short format

4. Use short output in scripts

--short removes the field label, but it does not choose a field by itself: combine it with the field you want.

$ lsb_release --id --short
Ubuntu
$ lsb_release --release --short
24.04
$ lsb_release --codename --short
noble

This is the useful shape for assigning a value:

distributor_id=$(lsb_release --id --short) || exit 1
release_codename=$(lsb_release --codename --short) || exit 1

printf 'distributor=%s codename=%s\n' "$distributor_id" "$release_codename"
  • Quote the variables when passing them to another command, and treat them as data, not shell syntax.
  • Do not write just lsb_release --short. On this implementation it selects no field, so it produces nothing and is not a useful test.
  • Check the exit status and validate that a required value is non-empty before using it to select a package source or feature path.

Checkpoint

The following verifies that the short codename is present without making any system change.

codename=$(lsb_release --codename --short) || exit 1
test -n "$codename" || { printf '%s\n' 'No distribution codename was reported' >&2; exit 1; }
printf 'codename: %s\n' "$codename"

5. Understand the version and source-file limits

The manual's --version description is easy to misread: it means LSB modules supported by the command, not the installed lsb-release package version. On this minimal implementation, the option is accepted and exits successfully, but it prints no module list in a non-interactive shell. Use dpkg-query on Debian-family systems when you need the package version instead.

$ lsb_release --version
$ printf 'status: %s\n' "$?"
status: 0

The data source is also a default, not a promise that every host has identical files. The program checks /etc/os-release when it is present and otherwise uses /usr/lib/os-release. If neither provides a field, the output can contain n/a rather than a value you can safely act on. Read the files for diagnosis, but do not edit them casually: they describe the operating system and may be managed by the distribution.

$ ls -l /etc/os-release /usr/lib/os-release
$ sed -n '1,12p' /etc/os-release

No elevated privilege is needed to inspect these usual locations. If permissions or a restricted execution environment prevent access, fix that environment or use the platform's supported identity interface. Do not make a service run as root merely to obtain a codename.

Common traps

  • Non-zero status normally means the command-line request or the underlying identification data could not be handled. Start with lsb_release --help, then check the executable and package version.
  • Unexpected value in a script? Print the raw field and inspect /etc/os-release before branching.
  • A familiar codename does not prove repository compatibility. Container images, vendor rebuilds and derivatives can expose an ID or release that does not match the software source you intend to use. Confirm the target project's supported distributions separately, and keep any package-source change behind its own review and rollback procedure. This guide performs no such change.

There is no undo step for the commands above, because they only read data and write one optional report under /tmp. If you created that report and no longer need it, inspect the exact path and then remove that single file:

$ test -f /tmp/lsb-release-report.txt && rm -- /tmp/lsb-release-report.txt

Done means

  • You can identify the installed binary and package version.
  • lsb_release --all gives you a human-readable distribution record.
  • You use --short with a selected field, not on its own.
  • Scripts check command status and reject an empty required value.
  • You know that --version is not the package-version query on this implementation.
  • No command changed packages, operating-system files, repositories or services.