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.
. /etc/os-release echo "$ID $VERSION_ID"
Try it
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.
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 withgrep/sed, so its variables, which includeNAMEandVERSION, do not overwrite your own. - Test
IDfirst, thenID_LIKE. Derivatives setID_LIKEto their parent, so onecasecan handle Ubuntu, Mint and Debian together. VERSION_IDis a string, not a number:22.04treated as a decimal number,22.04and22.4look different yet22.10would sort below22.4. Compare versions withsort -V.- Missing file: very old systems have
/etc/redhat-releaseor/etc/debian_versioninstead. - Containers report the image's distribution, not the host's. The kernel comes from the host (
uname -r). - Do not parse
PRETTY_NAMEfor logic. Its wording changes between releases. - macOS and BSD have no such file; use
uname -sto tell systems apart first.
Related
/etc/environment,uname,apk,pacman- Lessons: Packages, Services and systemd, Portability