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.
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
/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.
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:
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.
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
--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"
lsb_release --short. On this implementation it selects no field, so it produces nothing and is not a useful test.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"
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.
lsb_release --help, then check the executable and package version./etc/os-release before branching.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
lsb_release --all gives you a human-readable distribution record.--short with a selected field, not on its own.--version is not the package-version query on this implementation.