Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Special Files and Directories

The /etc/os-release file

Reference for /etc/os-release: the standard variables such as ID, VERSION_ID and ID_LIKE, how to source it in scripts, and how to branch on the distribution.

/etc/os-release is the standard place where a Linux distribution describes itself: its name, version and relatives. The format is simple: shell-compatible NAME=value lines. Because it is valid shell syntax, a script can load it with . (source) and then read the variables.

The real file is usually /usr/lib/os-release, with /etc/os-release a symlink to it. If the first is missing, fall back to the second. Use this file instead of guessing from uname, lsb_release or the presence of apt and yum.

Terminal
. /etc/os-release
echo "$ID $VERSION_ID"

Try it

Bash Reading the identification

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Choosing a package tool from ID and ID_LIKE

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Common variables (all optional except that ID and NAME have defaults):

Variable Description
NAME Name without version, for example Debian GNU/Linux.
PRETTY_NAME Human-readable name with version, good for display.
ID Lowercase identifier without spaces (debian, ubuntu, fedora, arch). Use this for scripts.
ID_LIKE Space-separated IDs of parent distributions (rhel fedora).
VERSION_ID Version number such as 10 or 22.04. Rolling releases leave it unset.
VERSION, VERSION_CODENAME Display version and codename (buster, jammy).
HOME_URL, SUPPORT_URL, BUG_REPORT_URL Web addresses.
VARIANT, VARIANT_ID, BUILD_ID Edition and build details used by some distributions.

Values may be quoted. There is no spacing around =.

Usage notes

  • Source it in a subshell (( . /etc/os-release; ... )) or read single values with grep/sed, so its variables, which include NAME and VERSION, do not overwrite your own.
  • Test ID first, then ID_LIKE. Derivatives set ID_LIKE to their parent, so one case can handle Ubuntu, Mint and Debian together.
  • VERSION_ID is a string, not a number: 22.04 treated as a decimal number, 22.04 and 22.4 look different yet 22.10 would sort below 22.4. Compare versions with sort -V.
  • Missing file: very old systems have /etc/redhat-release or /etc/debian_version instead.
  • Containers report the image's distribution, not the host's. The kernel comes from the host (uname -r).
  • Do not parse PRETTY_NAME for logic. Its wording changes between releases.
  • macOS and BSD have no such file; use uname -s to tell systems apart first.